简体   繁体   中英

a xmlhttprequest.send() crash in javascript

I was trying to learn XmlHttpRequest. I followed this W3School Tutorial .

in the file httprequest.0.js:

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

alert("A"); 
xmlhttp.open("GET","httprequest.0.xml",false);
alert("B"); 
xmlhttp.send(); // never succeeds this line !
alert("C");
xmlDoc=xmlhttp.responseXML; 
alert("D");

}

Everything seems to break at that line: xmlhttp.send();

are there exception catchers in Javascript or anything so as to manage such crash ? maybe xmlhttprequest states ?

in the file httprequest.0.html:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <!-- Scripts -->
    <script type="text/javascript" src="httprequest.0.js"></script>
</head>
<body onload="myHttpRequestFunction()">
    <h3>XMLHttpRequest</h3><p>
    <div id="RequestContent"> </div>    
</body>
</html>`

in the file httprequest.0.xml:

<root>Test Httprequest.0</root>

Do you have any advice ?

尝试发送此:

xmlhttp.send(null);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM