Regardless of whether the timeout occurs only within a few ms or more, the request will not be executed. The success callback function of your AJAX request will not be executed, and the request will end with the complete callback function. By default, all AJAX requests will have a timeout of 0 ms (unlimited), but it will hit the default browser timeout.
When the AJAX request expires, the error callback function will be called. The second argument to this function is a string describing the type of error, in which case it will be timeout . You can handle request timeouts by processing this callback function and optionally specifying a timeout value (if not specified, it works by default) in the body of the AJAX request:
$.ajax({ ... timeout: 5000, //specify the timeout value in milliseconds error: function(jqXHR, textStatus, errorThrown) { if(textStatus==="timeout") { //code to execute when timeout occurs } } });
In addition, you can also check if the request is programmed in the complete callback function (similar to the one shown above) by checking the second argument, which is a string, and will have a timeout value if the request was disconnected.
Also note:
The waiting period begins when $ .ajax is called; if several other requests are executed and there are no connections available in the browser, it is possible that the request will time out before it is sent.
Request timeouts usually either remain by default or are set as global defaults using $ .ajaxSetup (), rather than being overridden for specific requests with a timeout parameter.
I would suggest you use an alternative HTTP / s traffic monitoring tool like fiddler to find the secret of the second request.
More info: jQuery ajax documentation
source share