我收到了一个无法重现的错误报告,但 ajax 调用超时是目前的最佳猜测。
因此,我正在尝试查找 jQuery $.ajax()
调用的超时默认值。有人有想法吗?我在 jQuery 文档中找不到它。
我收到了一个无法重现的错误报告,但 ajax 调用超时是目前的最佳猜测。
因此,我正在尝试查找 jQuery $.ajax()
调用的超时默认值。有人有想法吗?我在 jQuery 文档中找不到它。
似乎没有标准的默认值。我感觉默认值为0
,超时事件完全依赖于浏览器和网络设置。
对于IE,XMLHTTPRequests有一个超时属性,在这里。它默认为null,并且说网络栈很可能是第一个超时的(顺便说一下,这不会生成ontimeout事件)。
$.ajax({
url: "/ajax_json_echo/",
timeout: 500,
error: function(jqXHR, textStatus, errorThrown) {
alert(textStatus); // this will be "timeout"
}
});
默认情况下没有超时。
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.