日期:2014-05-16 浏览次数:20725 次
<html> <head> <title>simpleAjax</title> <script type="text/javascript"> var xmlHttpRequest; function createXMLHttpRequest() { if (typeof XMLHttpRequest=="undefined") { xmlHttpRequest=new ActiveXObject(navigator.userAgent.indexOf("MSIE 5")>=0?"Microsoft.XMLHTTP":"Msxml2.XMLHTTP"); } else { xmlHttpRequest= new XMLHttpRequest(); } } function sendRequest() { createXMLHttpRequest(); xmlHttpRequest.onreadystatechange=stateChange; xmlHttpRequest.open("GET","test.xml"); xmlHttpRequest.send(null); } function stateChange() { if(xmlHttpRequest.readyState==4) { if(xmlHttpRequest==200) { window.alert(xmlHttpRequest.responseText); } } } </script> </head> <body> <form action="#"> <input type="button" value="send" onclick="sendRequest();"/> </form> </body> </html>
<html> <head> <title>simpleAjax</title> <script type="text/javascript"> var xmlHttpRequest; function createXMLHttpRequest() { if (typeof XMLHttpRequest == "undefined") { xmlHttpRequest = new ActiveXObject(navigator.userAgent.indexOf("MSIE 5") >= 0 ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP"); } else { xmlHttpRequest = new XMLHttpRequest(); } } function sendRequest() { createXMLHttpRequest(); //alert("df"); xmlHttpRequest.onreadystatechange = stateChange; xmlHttpRequest.open("GET", "test.xml"); xmlHttpRequest.send(null); } function stateChange() { if (xmlHttpRequest.readyState == 4) { if (xmlHttpRequest.status == 200) { alert("done"); alert(this.responseXML); } } } </script> </head> <body> <form action="#"> <input type="button" value="send" onclick="sendRequest();"/> </form> </body> </html>
------解决方案--------------------
不可能啊,在我的电脑上能执行的啊,而且xmlHttpRequest.status == 200而不是xmlHttpRequest == 200
------解决方案--------------------
你这些代码是放在jsp中的么?
------解决方案--------------------