jQuery html 响应
是否可以确定 $.ajax 返回的响应是从浏览器缓存提供的还是新鲜的?
谢谢。
Is it possible to determine if a response returned by $.ajax was served from the browser's cache or was fresh?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,那不可能。您可以做的是每次创建一个新的 URL(例如:通过将随机字符串附加到 URL,该字符串会被服务器上的脚本忽略),或者通过适当地设置响应的缓存标头。
请参阅:http://www.mnot.net/cache_docs/#CACHE-CONTROL
您可能需要设置
max-age
、no-store
、no-cache
、must-revalidate
或前一个的组合。No, that's not possible. What you can do is to create a new URL every time (eg: by appending a random string to the URL, which is ignored by the script on the server), or by setting the response's cache headers appropriately.
See: http://www.mnot.net/cache_docs/#CACHE-CONTROL
You might want to set
max-age
,no-store
,no-cache
,must-revalidate
or a combination of the previous.您可以在 jQuery 中使用以下内容来确保它不会缓存:
我不确定您想要实现什么。
如果你真的想知道数据是否过时,你可以这样做:
You can use the following in jQuery to make sure it does not cache:
Am not sure what you are looking to achieve.
If you really want to know if the data is stale, you can do something like: