javascript - Cannot access manifest-cached files with AJAX from webapp saved to Home screen in iOS devices, using jQuery.ajax() -
i'm making webapp. of files loads contain pure, static .json data. using jquery.ajax() (jquery 1.5.2) datatype:'json' , cache:true. works , files loaded. have configured cache manifest cache these json files (in addition css , js, , images). works there - when user visits site files need cached correctly (i have applicationcache event handlers confirm well). have tested in google chrome , can see files (including json ones) cached. when disconnect network, works (the jquery ajax calls automagically fetch cached json files).
now trying test on mobile safari (on actual ipad , iphone simulator). works expected when in safari - pages cached , on subsequent visits network disconnected, cached files used.
however, when add app home screen using "add home screen" in safari, app starts , .js, .css, , images work correctly, ajax calls don't! don't access cached .json files. each ajax call xmlhttprequest.status
0
, .statustext
error
, getallresponseheaders()
shows same (correct) headers in functional app in safari.
i don't this. limitation/bug in jquery's .ajax() or what? appreciated.
well, hate have answer own question, here i've done in case else runs problem:
apparently, when trying use $.ajax() in offline mode, request fetches cached files, returns 0 on xhmlhttprequest.status. having read on this, have seen status code of 0 can returned when user offline , when requesting local files. however, successful should report status code between 200 , 300. perhaps $.ajax() checks 200-300 status, otherwise request considered have failed.
to around this, added code error handler $.ajax()
request checks jqxhr.responsetext.**length**
. know correct number of characters in json files, if jqxhr.responsetext.length
same known value, consider request success , continue loading files. thing have add json.parse(jqxhr.responsetext)
in error handler, because data not parsed on status code 0.
Comments
Post a Comment