- 调试这段小例子的注意点是:(请看注释)
- <script language="JAVASCRIPT">
- var xmlHttp;
- function createXMLHttpRequest()
- {
- alert("createXMLHttpRequest()");
- if(window.ActiveXObject)
- {
- xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- else
- {
- xmlHttp=new XMLHttpRequest();
- }
- }
- function startRequest()
- {
- createXMLHttpRequest();
- xmlHttp.onreadystatechange=handleStateChange;//此处调用函数不加括号
- xmlHttp.open("GET","login.jsp",true);//此处的login.jsp 与加载此段js的页面文件在一个文件夹下.也可以这样说,此处用的是相对路径.
- xmlHttp.send(null);
- }
- function handleStateChange()
- {
- alert("handleStateChange()");
- if(xmlHttp.readyState==4)
- {
- if(xmlHttp.status==200)//此处是status 上一行是readyState
- {
- alert("The server replied with: "+xmlHttp.responseText);
- }
- }
- }
- </script>