关于 html:HTML5 缓存清单:不成功的 ajax 调用得到回退 | 珊瑚贝

HTML5 cache manifest: unsuccessful ajax calls getting fallback


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

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

1
2
3
4
5
NETWORK:
*

FALLBACK:
/ /offline

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

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

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

  • 您的意思是即使用户在线并且文件确实不存在,也会执行回退?
  • 是的,您希望在线通配符标志 (*) 覆盖您在回退中输入的内容。但根据规范,它的工作方式相反


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

1
2
3
4
$.ajax({
  url:”/data.html?”+ Math.random(),
  // other properties here…
});

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

这里有一个参考,因为报告状态码为0,可能会发生错误,这被解释为失败:

1
2
3
4
5
6
7
8
9
10
11
12
13
$.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’
});

来源:https://www.codenong.com/10879825/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9427.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?