首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

javascript函数有关问题

2013-07-08 
javascript函数问题simpleRequest.html代码!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//

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);
试试

热点排行