日期:2014-05-16  浏览次数:20524 次

javascript函数问题
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>


执行后,点击按钮后却并没有弹出任何窗口,不知道出错在哪里,还望大家帮帮忙找找别扭,在此谢过了
JavaScript HTML 函数 XMLHttpRequest

------解决方案--------------------
你是以http方式测试的吗
改成
alert("The server replied with:" + xmlHttp.responseXML);
试试