如何将 $.getJSON 超时设置为无限期
浏览器设置默认超时为 20 秒,但我希望它无限期地进行长轮询
最佳答案
使用 jQuery.ajaxSetup 和超时设置:
Set a timeout (in milliseconds) for the request. [..] 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.
http://api.jquery.com/jQuery.ajax/
http://api.jquery.com/jQuery.ajaxSetup/
$.ajaxSetup({
timeout: 0
});
关于jquery - 如何将 $.getJSON 超时设置为无限期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12950551/