此代码不会执行。我认为该xhttp.send()
功能有问题。因为alert
它执行之前的alert
函数但它没有执行之后的函数:
<html>
<head>
<title>PAGE OUTPUT</title>
<script type="text/javascript">
function aa()
{
var xhttp;
alert("hi welcome");
if(window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
alert("hi");
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET","vehicle.xml",false);
alert("OPEN EXECUTED");
xhttp.send();
alert("SEND EXECUTED");
xmlDoc=xhttp.responseXML;
alert("HI I HAVE REACHED OVER HERE");
var vehicle=xmlDoc.documentElement;
var car=vehicle.firstChild.nodeValue;
var price=car.firstChild.nodeValue;
alert(price);
}
</script>
</head>
<body>
<center><input type="submit" onclick="aa()"></center>
</body>