AJAX入门程序疑问。
实现first.html向simpleResponse.xml发生请求,返回文本 ,在html中弹出窗口现实。可是按钮没反应,不知道怎么回事!
下面是first.html
<html>
<head>
<title>example</title>
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}
}
function startRequest(){
createXMLHttpRequest();
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.open("GET","simpleResponse.xml",true);
xmlHttp.send(null);
}
function handleStateChange(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
alert("the server replied with:"+xmlHttp.responseText);
}
}
}
</script>
</head>
<body>
<form action="#">
<input name="按钮" type="button" onclick="startRequest();" value="start request"/>
</form>
</body>
</html>
simpleResponse里只有一串文体信息。
为什么会运行不了呢