jQuery html 响应

发布于 2024-09-18 17:43:58 字数 68 浏览 3 评论 0原文

是否可以确定 $.ajax 返回的响应是从浏览器缓存提供的还是新鲜的?

谢谢。

Is it possible to determine if a response returned by $.ajax was served from the browser's cache or was fresh?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忆梦 2024-09-25 17:43:58

不,那不可能。您可以做的是每次创建一个新的 URL(例如:通过将随机字符串附加到 URL,该字符串会被服务器上的脚本忽略),或者通过适当地设置响应的缓存标头。

请参阅:http://www.mnot.net/cache_docs/#CACHE-CONTROL

您可能需要设置 max-ageno-storeno-cachemust-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.

木槿暧夏七纪年 2024-09-25 17:43:58

您可以在 jQuery 中使用以下内容来确保它不会缓存:

$.ajaxSetup({cache: false}});

我不确定您想要实现什么。

如果你真的想知道数据是否过时,你可以这样做:

  1. 让你的服务器每次调用时都返回一个唯一的字符串
  2. 检查这个字符串是否存在于你的 javascript 临时变量中
  3. 如果是,则它是过时的,如果不,它是新的。

You can use the following in jQuery to make sure it does not cache:

$.ajaxSetup({cache: false}});

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:

  1. Make your server written return a unique string each and every time it is called
  2. Check if this string exists in your javascript temp variables
  3. If yes, its stale, if no, its new.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文