无法使用xmlhttprequest访问页面

时间:2018-10-05 05:38:16

标签: javascript c# ajax

我有一个在按钮上执行的xmlhttprequest代码,它运行并在第一次运行时访问advReqPage.aspx,但是当我再次按下按钮时,它将不再访问advReqPage.aspx。这里有什么问题?

function SaveAdvPayment() {
    var xhr = new XMLHttpRequest();
    var ornumber = document.getElementById("ORNumber").value;
    xhr.onreadystatechange = function () {
        if (xhr.readyState == XMLHttpRequest.DONE) {
            if (xhr.status === 200) {
                // OK
                alert('response:' + xhr.responseText);
                // here you can use the result (cli.responseText)
            } else {
                // not OK
                alert('failure!');
            }
        }
    }
    xhr.open("GET", "Server_Requests/advReqPage.aspx?poo=" + ornumber + "&sess=INSERT", false);
    xhr.send();
    alert('Saved');
    $('#myModal').modal('hide');
}    

1 个答案:

答案 0 :(得分:0)

第一个响应可能正在缓存中,当您发出第二个请求时,浏览器没有发出此新请求。此行为是由于浏览器锁定了缓存,并在再次请求相同资源之前等待查看一个请求的结果。您可以通过使请求变得唯一(例如添加随机查询字符串)来克服这一问题。