ton
ton

Reputation: 355

how to set $.getJSON timeout to indefinite

how to set $.getJSON timeout to indefinite

browser sets a default timeout of 20 secs but i want it indefinite for long polling

Upvotes: 3

Views: 2645

Answers (1)

jantimon
jantimon

Reputation: 38150

Use jQuery.ajaxSetup and the timeout setting:

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
});

Upvotes: 4

Related Questions