簡體   English   中英

Firefox和Chrome中Ajax POST的問題,但IE8中沒有

[英]Issue with Ajax POST in Firefox and Chrome but not IE8

我的以下代碼有問題。 當我在IE8中運行它時,如果從呼叫中成功返回,我會收到警報。

在Firefox和Chrome中不會發生這種情況,即在那運行它時我沒有任何警報。 其他一切工作正常,但在我看來,應該在調用成功后執行的代碼段失敗。

function stuffFile(file, wfid) {

    var xmlhttp = new XMLHttpRequest();

    if(window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

    var url = "http://someotherserver.page.aspx";
    var params = "fileName=" + file + "&param11=" + wfid;
    xmlhttp.open("POST", url, true);

    //Send the proper header information along with the request
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", params.length);
    xmlhttp.setRequestHeader("Connection", "close");

    xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
        //alert('onready');
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            var response = jQuery.trim(xmlhttp.responseText);
            alert('response ' + response);
        }
    }
    xmlhttp.send(params);


}

您已經在使用jQuery,則應該使用其AJAX功能。 它負責創建XMLHTTPRequest對象以及不同瀏覽器之間的所有差異,並完成了您手動執行的許多工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM