3

即使 URL 中包含 Math.random(), TLDR IE 仍在缓存我的请求。


所以我在我的网址末尾添加了数学随机:

var MYKMLURL = 'http://' + host + 'data/pattern?key='+ Math.random();

我还将数学随机添加到我的函数参数中:

window.setTimeout(RefreshPatternData, 1000, MYKMLLAYER);


           function RefreshPatternData(layer) {
               layer.loaded = false;
               layer.setVisibility(true);
               layer.refresh({ force: true, params: { 'key': Math.random()} });
               setTimeout(RefreshPatternData, 30000, MYKMLLAYER);
           }

因此请求显示为http://host/data/pattern?key=35678652545等。

每次发出请求时它都会更改。

它适用于 Firefox & Chrome & Safari 等。但 IE8 仍在缓存数据而不更新我的图层。

关于为什么会发生这种情况的任何想法?


所以我补充说:

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">

仍在缓存数据。还有什么想法吗?

4

2 回答 2

2

你可以试试这个帖子的答案:

防止 IE 缓存

于 2010-06-09T03:46:34.960 回答
2

我在 IE 上遇到了类似的问题,它缓存了 AJAX 请求。(为什么,上帝,你为什么要缓存AJAX请求?)在其他一切工作正常,但 IE 需要通过 HTTP 标头强制不缓存 AJAX 请求。

我早就忘记了网址,但请参阅: http: //greenash.net.au/thoughts/2006/03/an-ie-ajax-gotcha-page-caching/

此外,为我做的 HTTP 标头是:

Pragma: no-cache
Cache-Control: no-store, no-cache, must-revalidate
Cache-Control: post-check=0, pre-check=0

...我很诚实地从某处的网站上收集到。

于 2010-06-09T03:46:56.453 回答