jquery - ajax timeout callback function -
is there way run function if jquery's $.ajax function hits it's timeout
?
i.e.
$.ajax({ ... ... ,timeout:1000(){do if timeout) ... });
$.ajax({ ... timeout: 1000, error: function(jqxhr, textstatus, errorthrown) { if(textstatus==="timeout") { //do on timeout } } });
for more information check out jquery documentation:
http://api.jquery.com/jquery.ajax/
edited
it's been on year since answered , textstatus
possible values have changed "success", "notmodified", "error", "timeout", "abort",
or"parsererror"
. error callbacks, last 4 statuses possible.
also can wire error handlers through returned jquery deferred promise object's .fail
method:
var promise = $.ajax({ timeout: 1000 }); promise.fail(function(jqxhr, textstatus) { if(textstatus==="timeout") { // handle timeout } });
Comments
Post a Comment