jquery - 如何将 $.getJSON 超时设置为无限期

标签 jquery

如何将 $.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/

相关文章:

javascript - 解释 Math.floor(Math.random())

php - uploadify脾气暴躁?无法列出数据库中新上传的文件!

javascript - 如何在触发点击事件之前显示一个div

javascript - $.post() 之后的代码在 post-request 完成之前执行

javascript - 我需要一些帮助来修改 Apify 爬网程序

javascript - Backbone 错误无法调用 Deferred 方法

jquery - 循环遍历四个列表元素,应用 "active"类

javascript - 想使用 React Js 创建拖放组件

jQuery 选择器通过其大小来识别 div

javascript - 喝着 Jasmine 来运行我自己的类(class)