0

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(); ?

Finn
  • 1,323
  • 5
  • 24
  • 46

1 Answers1

1

you can try this:

$.ajax({
  url: "url",
  error: function(){
   //error code
  },
  success: function(){
   //success code
  },
  timeout: 3000 //ajax timeout
});
L.A.
  • 148
  • 7