JQuery ajax调用默认超时值

发布于 2024-08-26 05:07:16 字数 119 浏览 4 评论 0原文

我收到了无法复制的错误报告,但 ajax 调用超时是当前最好的猜测。

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

I got a bug report that I can't duplicate, but ajax-call timeout is the current best guess.

So I'm trying to find out the default value for timeout of a jQuery $.ajax() call. Anybody have an idea? Couldn't find it in jQuery documentation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

因为看清所以看轻 2024-09-02 05:07:16

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

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

There doesn't seem to be a standardized default value. I have the feeling the default is 0, and the timeout event left totally dependent on browser and network settings.

For IE, there is a timeout property for XMLHTTPRequests here. It defaults to null, and it says the network stack is likely to be the first to time out (which will not generate an ontimeout event by the way).

百变从容 2024-09-02 05:07:16

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

这是一个示例:

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

这里位于 jsfiddle

As an aside, when trying to diagnose a similar bug I realised that jquery's ajax error callback returns a status of "timeout" if it failed due to a timeout.

Here's an example:

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

Here it is on jsfiddle.

鹤舞 2024-09-02 05:07:16

默认情况下没有超时。

there is no timeout, by default.

不离久伴 2024-09-02 05:07:16

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

IE10和11不支持同步请求,其他浏览器也逐渐停止支持。这是由于制作它们会产生有害影响

更多信息可以在此处找到。

The XMLHttpRequest.timeout property represents a number of milliseconds a request can take before automatically being terminated. The default value is 0, which means there is no timeout. An important note the timeout shouldn't be used for synchronous XMLHttpRequests requests, used in a document environment or it will throw an InvalidAccessError exception. You may not use a timeout for synchronous requests with an owning window.

IE10 and 11 do not support synchronous requests, with support being phased out in other browsers too. This is due to detrimental effects resulting from making them.

More info can be found here.

撩心不撩汉 2024-09-02 05:07:16

请参考这个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.

Please refer to this api info.

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文