<html>
<head>
<script type="text/javascript">
var xmlhttp;
function loadXMLDoc()
{
xmlhttp=null;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open("GET","http://www.baidu.com",true);
xmlhttp.send(null);
}
else
{
alert("Your browser does not support XMLHTTP.");
}
}function state_Change()
{
if (xmlhttp.readyState==4)
{
var xmlDoc = xmlhttp.responseXML;
alert(xmlDoc);
alert("status is " + xmlhttp.status);//---------------------------------------->这个地方怎么老是0啊,在IE下可以收到200
if (xmlhttp.status==200)
{
alert("sucess");
alert(xmlhttp.responseText);
}
}
}
</script>
</head><body>
<h2>Using the HttpRequest Object</h2><p><b>Status:</b>
<span id="A1"></span>
</p><p><b>Status text:</b>
<span id="A2"></span>
</p><p><b>Response:</b>
<br /><span id="A3"></span>
</p><button onclick="loadXMLDoc()">Get XML</button></body>
</html>
以上是我的html
我的XMLHttpRequest无法获得正确的状态码
请各位般般忙,看看什么地方的问题。
<head>
<script type="text/javascript">
var xmlhttp;
function loadXMLDoc()
{
xmlhttp=null;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open("GET","http://www.baidu.com",true);
xmlhttp.send(null);
}
else
{
alert("Your browser does not support XMLHTTP.");
}
}function state_Change()
{
if (xmlhttp.readyState==4)
{
var xmlDoc = xmlhttp.responseXML;
alert(xmlDoc);
alert("status is " + xmlhttp.status);//---------------------------------------->这个地方怎么老是0啊,在IE下可以收到200
if (xmlhttp.status==200)
{
alert("sucess");
alert(xmlhttp.responseText);
}
}
}
</script>
</head><body>
<h2>Using the HttpRequest Object</h2><p><b>Status:</b>
<span id="A1"></span>
</p><p><b>Status text:</b>
<span id="A2"></span>
</p><p><b>Response:</b>
<br /><span id="A3"></span>
</p><button onclick="loadXMLDoc()">Get XML</button></body>
</html>
以上是我的html
我的XMLHttpRequest无法获得正确的状态码
请各位般般忙,看看什么地方的问题。
可以给个修正吗,要在火狐下可以跑的。