解决方法
我无法证明,但我希望这个脚本可以指导您找到解决方案:
您必须证明您的状态差异或来自“a.PHP”的每种响应类型的文本
$.ajax({ type: "GET",url: "a.PHP",complete: function (XMLHttpRequest,textStatus) { if (XMLHttpRequest.status!=200) // or responseText { var fn = arguments.callee; var _this = this; setTimeout(function(){fn.call(_this,XMLHttpRequest,textStatus);},200); } else { //ok } } });
或编辑:
complete: function xCompleteFunction(XMLHttpRequest,textStatus) { if (XMLHttpRequest.status!=200) // or responseText { var _this = this; setTimeout(function(){xCompleteFunction.call(_this,200); } else { //ok } }
编辑二:
将redirect.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <Meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <title></title> <script type="text/javascript"> $(function(){ $("#senddata").click(function(){ $.ajax({ type: "GET",complete: function xCompleteFunction(XMLHttpRequest,textStatus) { $("#info").append(""+XMLHttpRequest.status+"<br />"+XMLHttpRequest.responseText+"<br>"); if (XMLHttpRequest.status==301) // or responseText { var _this = this; setTimeout(function(){xCompleteFunction.call(_this,200); $("#info").append("waiting redirect<br>"); } else { $("#info").append("redirect ok<br>"); } } }); }); }); </script> </head> <body> <button id="senddata">send ajax request</button> <pre id="info"></pre> </body> </html>
a.PHP只会:
<?PHP for($a=0;$a<1000000;$a++) { //wait } header('Location: b.PHP');
b.PHP:
<?PHP print "hola mundo";