如何禁用 Ajax 缓存? [英] How to disable Ajax caching?
问题描述
我遇到了 ajax 缓存问题,这也是 IE 浏览器中的问题,但我通过编写以下代码修复了它.
I am having an issue with ajax caching, This was a problem in IE browser too but i fixed it by Writing the Following code.
response.setHeader("Cache-Control", "no-cache");
response.setHeader("expires","-1");
response.setHeader("pragma","no-cache");
但我看到 MAC 上的 Safari4.0 正在缓存 Ajax 请求(我们需要支持这一点).火狐从来都不是问题.关于这个过期",我将它设置为 -1,我看到很多地方将它设置为 0 或过去的某个旧日期.会有所作为吗?
But I see Safari4.0 on MAC is Caching the Ajax request(We have a requirment to support this). Fire Fox never a problem. Regarding this "Expire" i am setting it to -1, i see lot of places it is set 0 or some old date from past. Will it make a difference?
推荐答案
在您的 GET 请求中发送一个永远不会相同的额外参数,例如,当前时间戳.类似的东西:
Send an extra parameter with your GET request that will never be the same, for example, the current timestamp. Something like:
url = url + '&nocache=' + new Date().getTime();
这将阻止缓存.
这篇关于如何禁用 Ajax 缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!