HTML 5 offline and sAjaxSource question

HTML 5 offline and sAjaxSource question

_jthomas_jthomas Posts: 75Questions: 0Answers: 0
edited July 2011 in General
Hi Allan,
I have an interesting situation
I am trying out to make the application work offline using HTML 5 mechanisms. Everything downloads and is available in the application cache of the browser. However, when I go offline/bring down the web server, I get a 502 error on the sAjaxSource file

For e.g. I have the following in the HTML
[code]
"sAjaxSource": "customer/CustomerList.txt",
"bDeferRender": true,
[/code]

When I go "offline" and try to access it, browser is trying to request in the following format - Please note the "?_=1311633738059"
http://localhost:8080/offline/customer/CustomerList.txt?_=1311633738059 and since it is not in the application cache, the rendering fails. However, when I access using the following thru browser "http://localhost:8080/offline/customer/CustomerList.txt", the data is displayed from application cache. I can see this file in the cache - but do not know why the numbers are appended at the end of the sAjaxSource value

What is causing the appending of "?_=1311633738059" - is it because of Ajax? Is there a way to prevent this when browser tries to access the file "offline"? Please advise and Thanks very much.

Replies

  • _jthomas_jthomas Posts: 75Questions: 0Answers: 0
    Hi Allan,
    When you get a chance, could you look into this? Do I need to use fnServerData or some other mechanism to retrieve the data while offline?. Is the getJSON method is appending the callback fn or something at the end of request URL? Thanks very much.

    Regards
    Joson
  • _jthomas_jthomas Posts: 75Questions: 0Answers: 0
    Dropped the idea because we are hitting the 5MB limit per domain thing. Thanks
  • GregPGregP Posts: 500Questions: 10Answers: 0
    For future reference, yes you have it right. It's jQuery's ajax method (getJSON is just an alias for that) which will append the string specifically to avoid caching. I'm not sure which options are exposed to the .getJSON alias, but with plain old .ajax() you can set a parameter cache: true to allow caching.
  • _jthomas_jthomas Posts: 75Questions: 0Answers: 0
    aha... Thanks GregP
  • _jthomas_jthomas Posts: 75Questions: 0Answers: 0
    Just an update - I reconfirmed this by making the ajax calls "cached" in a very *bad* way to test it out and it worked. May be this code should be in the overriden "fnServerData" function in the config. I was lazy :-)

    Edited the following code in jquery.datatables.js - I changed "cache": false to "cache": true and I bring down the server and thing works!!! -
    [code]
    this.fnServerData = function ( url, data, callback, settings ) {
    settings.jqXHR = $.ajax( {
    "url": url,
    "data": data,
    "success": callback,
    "dataType": "json",
    "cache": true,
    "error": function (xhr, error, thrown) {
    if ( error == "parsererror" ) {
    alert( "DataTables warning: JSON data from server could not be parsed. "+
    "This is caused by a JSON formatting error." );
    }
    }
    } );
    };
    [/code]
  • GregPGregP Posts: 500Questions: 10Answers: 0
    Neat! Thanks for taking the time to test that.
This discussion has been closed.