78

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.

starball
  • 20,030
  • 7
  • 43
  • 238
Marcus
  • 5,083
  • 3
  • 32
  • 39
  • 1
    Hmm, I think this is browser specific. – Pekka Mar 24 '10 at 11:56
  • 1
    http://stackoverflow.com/questions/1342310/where-can-i-find-the-default-timeout-settings-for-all-browsers – Adriano Jul 02 '14 at 08:34
  • http://stackoverflow.com/questions/5798707/browser-timeouts – Adriano Jul 02 '14 at 08:38
  • 1
    possible duplicate of [What is jQuery's ajax default timeout value?](http://stackoverflow.com/questions/4148830/what-is-jquerys-ajax-default-timeout-value) – Pang Aug 01 '14 at 04:27

5 Answers5

52

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).

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • So basically jQuery doesn't use any default value for it. The problem was reported on Safari. I guess I'll just try to force some longish timeout value and hope for the best... Thanks! – Marcus Mar 24 '10 at 15:41
  • 1
    @Marcus : did it actually work? I could not find whether timeout always overrides the browser's timeout value (even if your ajax timeout value is bigger than the browser's) – Adriano Jul 02 '14 at 07:34
  • @AdrienBe At the time IIRC I couldn't duplicate the problem from the users bug report, but the timeout issue was the best guess at the moment. So I don't really have an answer. – Marcus Jul 02 '14 at 16:12
23

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:

$.ajax({
    url: "/ajax_json_echo/",
    timeout: 500,
    error: function(jqXHR, textStatus, errorThrown) {
        alert(textStatus); // this will be "timeout"
    }
});

Here it is on jsfiddle.

Jonathan Moffatt
  • 13,309
  • 8
  • 51
  • 49
  • Yes, see all error types http://stackoverflow.com/questions/3543683/determine-if-ajax-error-is-a-timeout – Adriano Jul 02 '14 at 07:36
7

there is no timeout, by default.

Jackie
  • 25,199
  • 6
  • 33
  • 24
2

The XMLHttpRequest.timeout property represents a number of milliseconds a request can take before automatically being terminated. The default value is 0, which means there is no timeout. An important note the timeout shouldn't be used for synchronous XMLHttpRequests requests, used in a document environment or it will throw an InvalidAccessError 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.

Bud Damyanov
  • 30,171
  • 6
  • 44
  • 52
0

Please refer to this api info.

timeout
Type: Number
Set a timeout (in milliseconds) for the request. A value of 0 means there 
will be no timeout. This will override any global timeout set with 
$.ajaxSetup(). 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.
Bhaskara Arani
  • 1,556
  • 1
  • 26
  • 44