0

<!DOCTYPE html>
<html>
<head>

<meta charset="utf-8">
<title>repeat</title>

</head>
<body>

<p>it seemed that the first Ajax should be vary easy!</p>
<p id="recieved"></p>
<input type="button" value="提交" onclick="getNewContent();">
<script>
    var request = false;
    try{
        request = new XMLHttpRequest();
    }catch(trymicrosoft){
        try{
            request = new ActiveXObject("Msxml2.XMLHTTP.6.0");
        }catch(earlier){
            try{
                request = new ActiveXObject("Msxml2.XMLHTTP.3.0");
            }catch(moreearlier){
                try{
                    request = new ActiveXObject("Msxml2.XMLHTTP");
                }catch(failed){
                    request = false;
                }
            }
        }
    }
    if (!request) alert("no Ajax here");
    function getNewContent(){
        if (request) {
            request.open("GET","target.xml",true);
            request.onreadystatechange = hhh;
            request.send(null);
        }            
    }
    function hhh() {
        if (request.readyState == 4) {
                //alert(request.status);
                console.log(request.status);
                var recievedText = document.getElementById('recieved');
                var responceT =document.createTextNode(request.responseText);
                recievedText.appendChild(responceT);
            
        }
    }
</script>

</body>
</html>

console.log(request.status)的结果分别如下:
firefox:

chrome:

请问为什么会有两种不同的status状态?如果用web上的服务器是不是不会出现这种差别?

查看全部 2 个回答