search

Home  >  Q&A  >  body text

javascript - The status value of local ajax request XMLHttpRequest is 0 in chrome and 200 in firefox, why?

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

天蓬老师天蓬老师2807 days ago516

reply all(2)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-19 10:36:56

    This blog has a detailed introduction

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

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-19 10:36:56

    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

    reply
    0
  • Cancelreply