11

我有一个 HTML5 应用程序,它使用缓存清单来提供离线功能。此应用程序在联机时进行 ajax 调用,其中一些调用可以获得 403 未授权响应。

这是我的 cache.manifest 文件的底部:

NETWORK:
*

FALLBACK:
/ /offline

如果我删除回退部分,所有接收 403 响应的 ajax 调用都会按预期工作,我可以使用 jQuery 错误处理程序检测到这一点并将用户重定向到登录表单。

但是如果存在回退部分,相同的调用会得到 200 OK 响应,回退 HTML 的内容作为正文,即使服务器回复了 403,所以我无法知道用户没有经过身份验证,必须发送到登录页面。

我在这里错过了什么吗?提前致谢

4

2 回答 2

2

将随机数作为查询参数添加到您要查找的 jQuery-AJAX 页面将解决该问题;IE

$.ajax({
  url: "/data.html?"+ Math.random(),
  // other properties here...
});
于 2012-09-07T07:35:46.510 回答
0

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

这是一个参考,由于将状态码报告为 0,因此可能会发生错误,这被解释为失败:

$.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'
});
于 2014-03-10T18:16:43.097 回答