JQuery ajax调用默认超时值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2507355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 13:39:28  来源:igfitidea点击:

JQuery ajax call default timeout value

jqueryajaxtimeoutdefault-value

提问by Marcus

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

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

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.

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

Thanks in advance, Marcus

提前致谢,马库斯

采纳答案by Pekka

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.

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

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 notgenerate an ontimeout event by the way).

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

回答by Jonathan Moffatt

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.

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

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.

这是在 jsfiddle 上

回答by lwpro2

there is no timeout, by default.

默认情况下没有超时。

回答by Bud Damyanov

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

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

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

IE10 和 11 不支持同步请求,其他浏览器也逐渐停止支持。这是由于制造它们造成的不利影响

More info can be found here.

更多信息可以在这里找到。