simpleRequest.html代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Simple XMLHttpRequest</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 handleStateChange() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
alert("The server replied with:" + xmlHttp.responseText);
}
}
}
function startRequest(){
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET","simpleResponse.xml",true);
xmlHttp.send(null);
}
</script>
</head> <body>
<input type="button" value="Start Basic Asynchronous Request"
onclick="startRequest()"/>
</body>
</html>
执行后,点击按钮后却并没有弹出任何窗口,不知道出错在哪里,还望大家帮帮忙找找别扭,在此谢过了JavaScriptHTML函数XMLHttpRequest
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Simple XMLHttpRequest</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 handleStateChange() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
alert("The server replied with:" + xmlHttp.responseText);
}
}
}
function startRequest(){
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET","simpleResponse.xml",true);
xmlHttp.send(null);
}
</script>
</head> <body>
<input type="button" value="Start Basic Asynchronous Request"
onclick="startRequest()"/>
</body>
</html>
执行后,点击按钮后却并没有弹出任何窗口,不知道出错在哪里,还望大家帮帮忙找找别扭,在此谢过了JavaScriptHTML函数XMLHttpRequest
改成
alert("The server replied with:" + xmlHttp.responseXML);
试试