JQuery ajax调用默认超时值

时间:2010-03-24 11:55:01

标签: jquery ajax timeout default-value

我收到了一个我无法复制的错误报告,但是ajax-call timeout是当前最好的猜测。

所以我试图找出jQuery $.ajax()调用超时的默认值。有人有想法吗?无法在jQuery文档中找到它。

提前致谢, 马库斯

5 个答案:

答案 0 :(得分:41)

似乎没有标准化的默认值。我觉得默认值为0,超时事件完全取决于浏览器和网络设置。

对于IE,XMLHTTPRequests here有一个超时属性。它默认为null,并且它表示网络堆栈很可能是第一个超时的(顺便说一下,不会生成ontimeout事件)。

答案 1 :(得分:17)

顺便说一句,在尝试诊断类似的错误时,我意识到jquery的ajax错误回调如果由于超时而失败则会返回“超时”状态。

以下是一个例子:

$.ajax({
    url: "/ajax_json_echo/",
    timeout: 500,
    error: function(jqXHR, textStatus, errorThrown) {
        alert(textStatus); // this will be "timeout"
    }
});

Here it is on jsfiddle

答案 2 :(得分:4)

默认情况下没有超时。

答案 3 :(得分:0)

XMLHttpRequest.timeout属性表示请求在自动终止之前可以花费的毫秒数。默认值为0,表示没有超时。重要的一点是,超时不应该用于文档环境中使用的同步XMLHttpRequests请求,否则会引发InvalidAccessError异常。对于具有拥有窗口的同步请求,您不能使用超时。

IE10和11不支持同步请求,支持也在其他浏览器中逐步淘汰。这是由于制作detrimental effects所致。

可以找到更多信息here

答案 4 :(得分:0)

请参考这个api信息。

timeout
Type: Number
Set a timeout (in milliseconds) for the request. A value of 0 means there 
will be no timeout. This will override any global timeout set with 
$.ajaxSetup(). The  timeout period starts at the point the $.ajax call is made; 
if several other  requests are in progress and the browser has no connections 
available, it is  possible for a request to time out before it can be sent. In 
jQuery 1.4.x and  below, the XMLHttpRequest object will be in an invalid state if 
the request  times out; accessing any object members may throw an exception. In 
Firefox 3.0+  only, script and JSONP requests cannot be cancelled by a timeout; 
the script  will  run even if it arrives after the timeout period.