Ajax拉缓存页面IE 8/9,但在FF中工作正常

时间:2012-04-25 20:12:30

标签: javascript ajax internet-explorer

很奇怪 - 我的ajax调用在IE中缓存,而它们在FF中正常运行;任何想法为什么?

function createRequestObject(){
    var req;
    if(window.XMLHttpRequest){
        //For Firefox, Safari, Opera
        req = new XMLHttpRequest();
    }
    else if(window.ActiveXObject){
        //For IE 5+
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else{
        //Error for an old browser
        alert('Your browser is not IE 5 or higher, or Firefox or Safari or Opera');
    }
    //alert (req);
    return req;
}

//Make the XMLHttpRequest Object
var http = createRequestObject();      

var head;

function sendRequestTwo(method, url, head1){
    head = head1
    if(method == "get" || method == "GET"){
        http.open(method,url);
        http.onreadystatechange = handleResponseTwo;
        http.send(null);
            }
}

function handleResponseTwo(){
    if(http.readyState == 4 && http.status == 200){
        var response = http.responseText;
        if(response){  
            document.getElementById(head).innerHTML = response;
            //window.scrollBy(0, 200);
        }
    }      
}

2 个答案:

答案 0 :(得分:3)

我遇到了同样的问题。 IE可以非常缓慢。

尝试为您的网址添加时间戳:

url += '?ts=' + new Date().getTime();

答案 1 :(得分:1)

IE积极地缓存ajax - 添加一个具有日期或其他独特之处的查询字符串,以防止它发生。