当前位置:编程学习 > XML/UML >>

xmlhttp.status==200为什么不等于200而是等于0

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
 function locadXMLDoc(){
  var xmlhttp;
  
  if(window.XMLHttpRequest){
   //code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp = new XMLHttpRequest();
  }else{
   //code for IE5, IE6
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  
  xmlhttp.onreadystatechange=function(){
  
   if(xmlhttp.readyState==4 && xmlhttp.status==200){//这个xmlhttp.status=0
   alert("aaa");
   alert(xmlhttp.status);
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    
   }
  }
  xmlhttp.open("GET","ajax/test1.txt",true);
  xmlhttp.send();
  
 }
</script>
</head>

<body>
 <div id = "myDiv"><h2>Let AJAX change this text</h2></div>
 <button type="button" onclick="locadXMLDoc()">通过 AJAX 改变内容</button>

</body>
</html>


程序开发疑难解惑:

xmlHttp.status==0
本地响应成功。
0表示本地,把if(xmlHttp.status==200)改成
if(xmlHttp.status==200   ||   xmlHttp.staus==0)

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,