xuxiangpan888 发表于 2013-1-29 12:49:03

ajax超时

var havereturn=false; function ontimeout(){   if(!havereturn){   //还没返回,    alert("连接超时");   havereturn=true;   //也许有什么办法让xmlhttp停下来,可以写在这,不停也没关系。         //window.clearTimeout();       //ajax.abort();   //ajax = null;   //delete ajax;   } } function doYourAjax(){//------你的ajax请求 var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP") xmlhttp.onreadystatechange=function(){   if (xhr.readyState == 4) {   if (xhr.status == 200) {      if(!havereturn){         //你处理返回结果的代码         var res = xmlhttp.responseText;         alert(res);      }   }   havereturn=true;   } } havereturn=false; xmlhttp.Open("POST", "www.iteye.com"); setTimeout("ontimeout()",5000);//5秒后执行ontimeout xmlhttp.Send(data); }//---------
页: [1]
查看完整版本: ajax超时