che*_*eng 1 javascript ajax status
我正在尝试从本地计算机上的远程服务器获取信息.readyState没有问题,即== 4.但是,当我按下按钮时状态总是0(而不是200),它什么也不返回.
这是代码,:
<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET",'http://www.spartanbook.com/textbooks_xml.asp?control=campus&campus=45&term=80',true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
它基本上来自w3shcools.只需更换网址.当我将其粘贴到浏览器的地址栏中时,我正在使用的网址正在运行.
任何的想法?谢谢!!
检查您是否未提出跨域请求.
例如,如果您没有从http://www.spartanbook.com提供此页面,那么预期结果将被拒绝访问,这奇怪的是,readyState为4,但状态为0.
如果您需要发出跨域请求,则需要使用代理.
| 归档时间: |
|
| 查看次数: |
10139 次 |
| 最近记录: |