Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect a timeout using the global jQuery Ajax event handler

Tags:

jquery

ajax

Global Ajax event handlers that are attached with jQuery.ajaxError or jQuery.ajaxComplete don't seem to receive any information about whether a fetch failure is as a result of a time out. Any pointers on how I can detect time outs? Would checking to see if the status property of the jqXHR object is 0 be a reliable method?

like image 600
Ates Goral Avatar asked Mar 24 '11 06:03

Ates Goral


1 Answers

Probably there are some differences how you defined the global jQuery Ajax event handler. You don't posted your code. I tried the following

$(document).bind("ajaxError", function (e, jqXHR, ajaxSettings, thrownError) {
    // log the event
});
$(document).bind("ajaxComplete", function (e, jqXHR) {
    // log the event
});

with jQuery 1.7.1 and I can see that in case of timeout error always both ajaxError and ajaxComplete was called.

You can verify this in the simple demo which display in my tests either

enter image description here

in case of success or

enter image description here

on timeout error.

like image 130
Oleg Avatar answered Sep 18 '22 06:09

Oleg