[英]How to disable timeout in jQuery and CasperJS
My CasperJS
script calls via jQuery
an PHP script
. 我的CasperJS
脚本通过jQuery
调用了PHP script
。 Problem is, that the PHP script takes around 70 sec to excute, but somehow CasperJS or jQuery are canceling the request after around 30 sec and throw the error: Error: NETWORK_ERR: XMLHttpRequest Exception 101
. 问题是,PHP脚本执行大约需要70秒,但是CasperJS或jQuery在大约30秒后以某种方式取消了请求并抛出错误: Error: NETWORK_ERR: XMLHttpRequest Exception 101
。
Code to call the PHP script: 调用PHP脚本的代码:
var result = casper.evaluate(function(){
$.ajaxSetup({'async':false});
var result = $.get('http://localhost/full.php', function() {} );
return result;
});
I tried the following solutions: 我尝试了以下解决方案:
// For CasperJS:
pageSettings: {
timeout: 999999999
}
// For jQuery
$.ajaxSetup({'timeout':999999999});
Also I made sure that the executed PHP script is not the cause for the error (I made a test-script with all used functions, which only takes some seconds to execute. This works fine). 另外,我还确保执行的PHP脚本不是导致错误的原因(我用所有使用过的功能制作了一个测试脚本,只需花费几秒钟即可执行。这很好用)。
I read that jQuery has no timeout by default and that CasperJS throws an error, when a timeout occurs. 我读到jQuery默认没有超时,并且当发生超时时CasperJS会引发错误。 But somehow it must be timeout error, because it always occurs after around 30 sec. 但是由于某种原因,它一定是超时错误,因为它总是在30秒后发生。 (btw.. the PHP script uses set_time_limit(0);
) (顺便说一句。PHP脚本使用set_time_limit(0);
)
Thanks for any suggestions! 感谢您的任何建议!
Also I made sure that the executed PHP script is not the cause for the error (I made a test-script with all used functions, which only takes some seconds to execute. This works fine). 另外,我还确保执行的PHP脚本不是导致错误的原因(我用所有使用过的功能制作了一个测试脚本,只需花费几秒钟即可执行。这很好用)。
It's maybe the problem. 可能是问题所在。 Did you tried when you script when it takes 70 s ? 您花70秒编写脚本时是否尝试过? Php has also a maximum execution time setting as said here . 如这里所说,Php还具有最大执行时间设置。 By default, it's 30 secs. 默认情况下为30秒。 Try to test in the same scenario. 尝试在相同的情况下进行测试。
Jsut for futures references, the default Jquery Ajax Timeout is 0 (technically it's undefined, but behaves as 0). 对于期货参考,Jsut的默认Jquery Ajax超时值为0(从技术上讲它是未定义的,但表现为0)。 This means no timeout in jQuery itself... You could specify one via $.ajax ({timeout: XXXX })
or $.ajaxSetup ({timeout: XXXX })
. 这意味着jQuery本身没有超时...您可以通过$.ajax ({timeout: XXXX })
或$.ajaxSetup ({timeout: XXXX })
指定一个。 The complete callback contains a string categorizing the status of the request ("success", "notmodified", "error", "timeout", "abort", or "parsererror"). 完整的回调包含对请求状态进行分类的字符串(“成功”,“未修改”,“错误”,“超时”,“中止”或“ parsererror”)。
There is also two timeouts in casperJs : timeout and steptimeout . CasperJs中还有两个超时: 超时和步进超时 。 There are also two callback ontimeout
and on steptimout
that are executed when script/step execution time exceeds these limits. 当脚本/步骤执行时间超过这些限制时, steptimout
执行两个回调ontimeout
和steptimout
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.