日期:2014-05-16  浏览次数:20783 次

ajax报错!“完成该操作所需的数据还不可使用”
功能是这样的.从服务器端连续的读几个文件。
-----------------、


var xmlHttp=null;
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

xmlHttp.open("get",url,true); //url=http://xxxx/a.txt 或者 b.txt

try {
   xmlHttp.send();
   if(xmlHttp.readyState==4 && xmlHttp.status==200) {
          var objFile = xmlHttp.responseText; //出错行
    }
}
catch(err) {
     alert(err.message);
}



问题是:当第一次读a.txt(1M)的时候,是没有问题的。但读第二次b.txt(10M)的时候,报了个“完成该操作所需的数据还不可使用”的错误。这是为什么阿?

------解决方案--------------------
我以前遇到这个提示的时候,是因为后台设置了断点。前台还没有接受到数据。
------解决方案--------------------
跟文件大小有关系?
------解决方案--------------------
会不会是responseText ajax对象缓存的问题
------解决方案--------------------
放在 这个事件中 onreadystatechange中



var xmlHttp=null;
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
 
xmlHttp.open("get",url,true); //url=http://xxxx/a.txt 或者 b.txt
xmlhttp.onreadystatechange=function(){
 if(xmlHttp.readyState==4 && xmlHttp.status==200) {
          var objFile = xmlHttp.responseText; //出错行
    }
}

   xmlHttp.send();

}

------解决方案--------------------
引用:
放在 这个事件中 onreadystatechange中JavaScript code?12345678910111213var xmlHttp=null;xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");  xmlHttp.open("get",url,true); //url=http://xxxx/a.txt 或者 b……
说的对,你是异步的执行,应该用这种方式的。