HTML5 cache manifest: unsuccessful ajax calls getting fallback
Asked Answered
D

2

11

I've got an HTML5 application which uses a cache manifest to provide offline functionality. This application makes ajax calls, when online, and some of this calls can obtain a 403 unauthorized in response.

Here's the bottom of my cache.manifest file:

NETWORK:
*

FALLBACK:
/ /offline

If I remove the fallback section, all the ajax calls receiving a 403 response work as expected and I can detect this with jQuery error handler and redirect the user to the login form.

But if fallback section is present, the same calls get a 200 OK response, with fallback HTML's content as body, even though the server replied with a 403, so there's no way for me to know the user is not authenticated and must be sent to the login page.

Am I missing something here? Thanks in advance

Dally answered 4/6, 2012 at 10:28 Comment(2)
Do you mean the fallback gets executed even when the user is online and the file really doesn't exist?Bamberg
Yes, you are expecting the online wildcard flag (*) to override what you entered in the fallback. But it works the other way around, per the specJonette
S
2

Adding a random number as query-parameter to the page you're looking for to the jQuery-AJAX will solve the issue; i.e.

$.ajax({
  url: "/data.html?"+ Math.random(),
  // other properties here...
});
Stark answered 7/9, 2012 at 7:35 Comment(0)
P
0

From http://alistapart.com/article/application-cache-is-a-douchebag#latest

Here is a reference that errors can occur because of the reporting of the status code as 0, which is interpreted as a failure:

$.ajax( url ).always( function(response) {
 // Exit if this request was deliberately aborted
 if (response.statusText === 'abort') { return; } // Does this smell like an error?
 if (response.responseText !== undefined) {
  if (response.responseText && response.status < 400) {
   // Not a real error, recover the content    resp
  }
  else {
   // This is a proper error, deal with it
   return;
  }
 } // do something with 'response'
});
Perionychium answered 10/3, 2014 at 18:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.