javascript - The status value of local ajax request XMLHttpRequest is 0 in chrome and 200 in firefox, why?
天蓬老师
天蓬老师 2017-05-19 10:34:56
0
2
522

<!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>

The results of

console.log(request.status) are as follows:
firefox:

chrome:

Why are there two different statuses? Will this difference not occur if we use a server on the web?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
淡淡烟草味

This blog has a detailed introduction

http://blog.csdn.net/iaiti/ar...

我想大声告诉你

ajax was originally designed to be used on the server. It shouldn't be available locally. Something concrete. You can use chrome to open network and FF to open network to view

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template