小编Abd*_*lik的帖子

onreadystatechange函数在AJAX中不起作用

就XMLHttpRequest()对象而言,它很好,问题在于onreadystatechange,例如,如果我以这种方式放置代码,它就完美了.

function process(){
    var xmlHttp = new XMLHttpRequest();

    if(xmlHttp){
        xmlHttp.onreadystatechange = function(){
            theD = document.getElementById("theD");
            if(xmlHttp.readyState == 1){
                theD.innerHTML += "Status 1: Server connection established ! <br/>";
                }
            else if(xmlHttp.readyState == 2){
                theD.innerHTML += "Status 2: Request recieved ! <br/>";
                }
            else if(xmlHttp.readyState == 3){
                theD.innerHTML += "Status 3: Processing Request ! <br/>";
                }
            else if(xmlHttp.readyState == 4){

                if(xmlHttp.status == 200){
                    var text = xmlHttp.responseText;
                    theD.innerHTML += "Status 4: Processing Request ! <br/>";
                    theD.innerHTML += text;
                    }
                else{ …
Run Code Online (Sandbox Code Playgroud)

javascript ajax

3
推荐指数
2
解决办法
2万
查看次数

标签 统计

ajax ×1

javascript ×1