0

I am working with a very poorly done endpoint...So please understand that I won't be able change how this endpoint behaves.

This ajax call is: POST /doStupidThing/.

Given a list of ids, I need to call the endpoint for each id. How can I make sure the call doesn't get fired before the previous call completes ? Should I just set async to false ?

  • Why would you want to disable async processing in this case, have a larger number of calls is exactly where you would want to take advantage of async processing. If number is too large, I can understand you might need to limit number of concurrent connections, but seems backwards to me. – Gary Walker Aug 24 '13 at 00:16
  • The backend code is not thread safe. – user2712654 Aug 28 '13 at 22:02

2 Answers2

0

Yes, you can try setting async to false

Aaron Gong
  • 842
  • 8
  • 18
0

Just for the record, the better way to do things would be to set yourself up to use the Jquery promise interface

This SO answer covers this in more detail and talks about deferred objects.

One thing you can do is make your next ajax call in your .done function.

function SecondAjax() { 
$.ajax({
      type: "POST",
      url: "example.php",
      data: data_obj,
      dataType: "html"
   }).done(function(msg) {
         #You can put a third one in here
         #This should also give you an idea of how to loop.
      }
}

function firstAjax() { 
$.ajax({
      type: "POST",
      url: "example.php",
      data: data_obj,
      dataType: "html"
   }).done(function(msg) {
         SecondAjax()
      }
}
Community
  • 1
  • 1
AlexLordThorsen
  • 6,777
  • 2
  • 39
  • 82