AJAX返回status的值经常是-1
代码如下,不知道各位有没有遇见过这种问题。代码不是运行在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);
}
...全文
相关推荐
jQuery AJAX中readyState与status的区别与联系
主要介绍了 jQuery AJAX中readyState与status的区别与联系,非常不错,具有参考借鉴价值,需要的朋友可以参考下
jQuery Ajax向某个页面传值并取得返回的数组
jQuery Ajax向某个页面传值并取得返回的数组
Servlet 与 Ajax 交互一直报status=parsererror的解决办法
主要介绍了Servlet 与 Ajax 交互一直报status=parsererror的解决办法,非常不错,具有参考借鉴价值,需要的朋友可以参考下
Ajax请求的五个步骤!!!
IT人员
jquery ajax修改全局变量示例代码
今天工作的时候遇到一个问题 代码如下: 代码如下: var status=1; var ob=$(“[name=’email’]”); $.ajax({ url:”{:U(‘Home/Index/checkemail’)}”, data:”email=”+query.email, type:”post”, dataType:”json”, success:function(re){ status=0; } }); alert(status); 这样每次弹出来的都是1 ; 因为想根据回传的值进行处理 将status改变其值,查了些资料 解决方案:async:false, 改写成: 代码如下


