mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-04-27 01:24:41 +00:00
add documentation around application cache issues and a suggested workaround
This commit is contained in:
parent
8e6a67d3bb
commit
4829928ca1
1 changed files with 21 additions and 0 deletions
|
|
@ -101,6 +101,27 @@
|
|||
|
||||
<p>Form submissions are handled automatically through the navigation model as well. Visit the forms section for more information.</p>
|
||||
|
||||
<h2>Using the Application Cache</h2>
|
||||
|
||||
<p>When using the application cache with jQuery Mobile there is at least one important issue to consider. Some browsers, when making requests to the cache will report an http status of 0 on success. This causes jQuery Core's <code>$.ajax</code> to trigger error handlers. The suggested workaround for users leveraging the application cache is to use a jQuery ajax pre-filter. Something like the following (credit to <a href="https://github.com/jammus">jammus</a>):</p>
|
||||
|
||||
<pre><code>
|
||||
|
||||
$.ajaxPrefilter( function(options, originalOptions, jqXHR) {
|
||||
if ( applicationCache &&
|
||||
applicationCache.status != applicationCache.UNCACHED &&
|
||||
applicationCache.status != applicationCache.OBSOLETE ) {
|
||||
// the important bit
|
||||
options.isLocal = true;
|
||||
}
|
||||
});
|
||||
|
||||
</code></pre>
|
||||
|
||||
<p>Setting <code>isLocal</code> to true for your ajax requests will alert jQuery Core that it should handle the 0 return values differently. Local requests exhibit similar behavior (ie 0 statuses), and Core will then fall back to determining success based on the presence of content in the xhr <code>responseText</code> attribute.</p>
|
||||
|
||||
<p>One important issue to note with the above is that it will set <code>isLocal</code> to true for all requests made via ajax regardless of whether they are in the manifest or not so long as the cache is valid. This works for now because Core only consults the <code>isLocal</code> value when the status is in fact 0 which doesn't affect uncached results. There is no long term guarantee that <code>isLocal</code> will remain isolated in it's purpose for handling 0 status values. If that changes it may break your application.</p>
|
||||
|
||||
<h2>Known limitations</h2>
|
||||
|
||||
<p>The non-standard environment created by jQuery Mobile's page navigation model introduces some conditions for which you should be aware when building pages:</p>
|
||||
|
|
|
|||
Loading…
Reference in a new issue