ajax后台请求页面,readyState有时能到4,返回数据,有时就一直为1,返回不了数据,怎么办,该如何解决呢?谢谢各位大侠帮忙啊!!!即使是请求同一个页面,也有时能得到4,有时一直为1,代码如下
var http_request=false;
if(window.XMLHttpRequest){
http_request=new XMLHttpRequest();
if(http_request.overrideMimeType){
http_request.overrideMimeType("text/xml");
}
}else if(window.ActiveXObject){
try{
http_request=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
http_request=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
}
}
}
if(http_request){
http_request.onreadystatechange=getAbc;
http_request.open("GET","/test.jsp" ,true);
http_request.send(null);
}function getAbc(){
if(http_request.readyState==4){
if(http_request.status==200){
alert("abc");
}
}
}
}
}
var http_request=false;
if(window.XMLHttpRequest){
http_request=new XMLHttpRequest();
if(http_request.overrideMimeType){
http_request.overrideMimeType("text/xml");
}
}else if(window.ActiveXObject){
try{
http_request=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
http_request=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
}
}
}
if(http_request){
http_request.onreadystatechange=getAbc;
http_request.open("GET","/test.jsp" ,true);
http_request.send(null);
}function getAbc(){
if(http_request.readyState==4){
if(http_request.status==200){
alert("abc");
}
}
}
}
}
alert(printhttp_request.readyState);
if(printhttp_request.readyState==4){
有时弹出
1
1
undefined
undefined
undefined
也有时弹出
1
1
3
4
2(状态:0 = uninitialized
1 = loading
2 = loaded
3 = interactive
4 = complete)
请大家帮我分析一下原因及解决方案,多谢了!