当前位置:编程学习 > JS >>

Ajax中readyState返回值为0

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
 var xmlHttp;
 function createXMLHttpRequest(){
  if(window.XMLHttpRequest){
   xmlHttp = new XMLHttpRequest();
  }else if(window.ActiveXObject){
   xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
 function handleRequestChange(){
  alert(xmlHttp.readyState);
  alert(xmlHttp);
  if(xmlHttp.readyState == 4){
   if(xmlHttp.status == 200){
    document.getElementById("result").innerHTML = xmlHttp.responseText;
   }  
  }
 }
 function startRequest(){
  createXMLHttpRequest();
  xmlHttp.onreadystatechange = handleRequestChange();
  xmlHttp.open("GET","info.jsp",true);
  xmlHttp.send(null);
 }
</script>
</head>
<body>
 <table>
  <tr><td>username</td><td><input type="text" onblur="startRequest();"/></td></tr>
  <tr><td>password</td><td><input type="password"/></td></tr>
  <tr><td colspan="2"><span id="result"></span></td></tr>
 </table>
</body>
</html>
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,