AJAX返回status的值经常是-1

绿野仙踪 2011-04-06 03:11:24
代码如下,不知道各位有没有遇见过这种问题。代码不是运行在IE里,是widget。开发文档里写的支持javascript,但是用ajax请求数据时,有时候就会出xhr.status = -1 的情况,其他时候正常返回status =200 。请各位大侠帮忙解答

function getNews(id,url,type,sort)
{
var xhr;
//call the right constructor for the browser being used
if (window.ActiveXObject)
xhr = new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest)
xhr = new XMLHttpRequest();
else
alert("AJAX request not supported");

//prepare the xmlhttprequest object
xhr.open("GET", url, true);
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("Pragma", "no-cache");
xhr.onreadystatechange = function() {
if (xhr.readyState == 4)
{
if (xhr.status == 200)
{
if (xhr.responseText != null)
{
//process sina news
processNews(xhr.responseXML, id,type,sort,url);
}
else
{
alert("Failed to receive RSS file from the server - file not found.");
return false;
}
}
else
{
alert("Error code " + xhr.status + " received: " + xhr.statusText);
}
}
}
//send the request
xhr.send(null);
}

...全文
222 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Mr-Jee 2011-04-06
  • 打赏
  • 举报
回复
不知道你的这个插件是什么东西
我知道的状态码都是1XX 2XX 3XX 4XX 5XX
-1这个状态码没见识过。

87,997

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧