使用AJAX时没有清除缓存查询字符串,但使用HTTP响应头清除IE缓存缓存、字符串、AJAX、HTTP

2023-09-10 20:03:38 作者:初衷

我有经典的IE浏览器的缓存,一切功能于阿贾克斯的问题。我有一点数据每分钟刷新的。

已经研究了论坛的解决方案可以归结为这些选项(http://stackoverflow.com/questions/5997857/grails-best-way-to-send-cache-headers-with-every-ajax-call):

一个缓存阻止令牌添加到查询字符串(如?时间= [时间戳]) 发送一个HTTP响应头,专门禁止IE缓存的要求 使用,而不是一个GET ajax的POST

不幸的是,明显的querysting或缓存:假,我作为更新的数据文件被托管在Akamai的设置的NetStorage将无法正常工作,也不能接受查询字符串。我不想使用POST两种。

我想要做的就是尝试发送一个HTTP响应头,专门禁止IE缓存的要求或是否有人知道另一种清除缓存解决方案??

有谁知道这可能是做了什么?任何帮助将是非常美联社preciated。

下面是我的code:

 (功能($){
VAR定时器= 0;
VAR浏览器= {
    版本:函数(){
        变种版本= 999;
        如果(!navigator.appVersion.indexOf(MSIE)= -1)版本= parseFloat(navigator.appVersion.split(MSIE)[1]);
        返回版本;
    }
}
$ .fn.serviceboard =功能(选件){
    VAR设置= {刷新:60};

    返回this.each(函数(){
        如果(选件)$ .extend(设置,选项);
        VAR OBJ = $(本);
        GetLatesData(OBJ,settings.refresh);
        如果(settings.refresh> 9&安培;&安培; Browser.Version()→6){
            定时器=的setInterval(函数(){GetLatestData(OBJ,settings.refresh)},settings.refresh * 1000);
        }
    });
};
功能GetLatestData(OBJ,刷新){
    VAR _url =/path/updated-data.htm;
    $阿贾克斯({
        网址:_url,
        数据类型:HTML,
        完成:函数(){},
        成功:功能(数据){
            。obj.empty()追加(数据);
            }
        }
    });
}
})(jQuery的);
 

解决方案

添加一个随机数的GET请求,使IE浏览器将不会在其高速缓存标识为相同的。这个号码可以是一个时间戳:

 新的Date()。的getTime()
 
Ajax

修改或许会让请求的URL:

  VAR _url =/path/updated-data.htm? +新的Date()。的getTime()
 

这应该不会造成我相信任何错误。

EDIT2 对不起,我刚才看了你的帖子好一点,只见这不是一个选择。

您说的托管在Akamai和不能接受查询字符串,但为什么不呢? 我从来没有听说过一个网页,将不接受额外的:?布拉布拉,即使它的HTML

I'm having the classic IE-caches-everything-in-Ajax issue. I have a bit of data that refreshes every minute.

Having researched the forums the solutions boil down to these options (http://stackoverflow.com/questions/5997857/grails-best-way-to-send-cache-headers-with-every-ajax-call):

add a cache-busting token to the query string (like ?time=[timestamp]) send a HTTP response header that specifically forbids IE to cache the request use an ajax POST instead of a GET

Unfortunately the obvious querysting or "cache: false" setting will not work for me as the updated data file is hosted on Akamai Netstorage and cannot accept querystrings. I don't want to use POST either.

What I want to do is try send an HTTP response header that specifically forbids IE to cache the request or if anyone else knows another cache busting solution??

Does anyone know how this might be done? Any help would be much appreciated.

Here is my code:

(function ($) {
var timer = 0;
var Browser = {
    Version: function () {
        var version = 999;
        if (navigator.appVersion.indexOf("MSIE") != -1) version = parseFloat(navigator.appVersion.split("MSIE")[1]);
        return version;
    }
}
$.fn.serviceboard = function (options) {
    var settings = { "refresh": 60};

    return this.each(function () {
        if (options) $.extend(settings, options);
        var obj = $(this);
        GetLatesData(obj, settings.refresh);
        if (settings.refresh > 9 && Browser.Version() > 6) {
            timer = setInterval(function () { GetLatestData(obj, settings.refresh) }, settings.refresh * 1000);
        }
    });
};
function GetLatestData(obj, refresh) {
    var _url = "/path/updated-data.htm";
    $.ajax({
        url: _url,
        dataType: "html",
        complete: function () {},
        success: function (data) {  
            obj.empty().append(data);               
            }
        }
    });
}
})(jQuery);

解决方案

Add a random number to the GET request so that IE will not identify it as "the same" in its cache. This number could be a timestamp:

new Date().getTime()

EDIT perhaps make the requested url:

var _url = "/path/updated-data.htm?" + new Date().getTime()

This shouldn't cause any errors I believe.

EDIT2 Sorry I just read your post a bit better and saw that this is not an option for you.

You say "is hosted on Akamai and cannot accept querystrings" but why not? I've never heard of a page that won't accept an additional: "?blabla", even when it's html.

 
精彩推荐
图片推荐