JQuery ajax调用默认超时值
我收到了无法复制的错误报告,但 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
似乎没有标准化的默认值。我感觉默认值是
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).
顺便说一句,当尝试诊断类似的错误时,我意识到如果由于超时而失败,jquery 的 ajax 错误回调会返回“超时”状态。
这是一个示例:
这里位于 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:
Here it is on jsfiddle.
默认情况下没有超时。
there is no timeout, by default.
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 is0
, which means there is no timeout. An important note the timeout shouldn't be used for synchronousXMLHttpRequests
requests, used in a document environment or it will throw anInvalidAccessError
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.
请参考这个api信息。
Please refer to this api info.