Reputation: 1459
if I have a synchronous communication ajax ($.ajax function), how to set a timeout for the ajax.
When the countdown ends, via function or any way to return false.
I want to achieve this approach:
ex:
if $.ajax is not timeout
=> call function A() or do something;
else if $.ajax is timeout
=> call function B() or do something;
maybe, detection the working time through other function,ex: javascript setInterval();,setTimeout(); ?
Upvotes: 0
Views: 553
Reputation: 147
you can try this:
$.ajax({
url: "url",
error: function(){
//error code
},
success: function(){
//success code
},
timeout: 3000 //ajax timeout
});
Upvotes: 1