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 ?
try sending this:
xmlhttp.send(null);
精彩评论