0

I have a function that do multiple ajax call and I have to make those call 1 by 1

At the beginning of the function I disable the button add to cart and I show a div with an animated image (loading gif), then , I loop through all my ajax call.

function add_cart_tour()
    {
        // this code is executed after my ajax call ...
        $("#btn_ajouter").prop('disabled' , true);
        $("#please_wait").show();

        // loop in all call
        // when all call are done, I redirect the user to the cart page
    }

Why this async false call is blocking the code before I even made the call ?

user2942945
  • 469
  • 1
  • 7
  • 19
  • 1
    If you're asking why does the application hold up when async is false, that's because you're trying to run synchronous requests: or in other words, your program will do nothing until it gets a response (which can be a while, and why async is preferred) – Patrick Barr May 31 '17 at 19:28
  • $("#btn_ajouter").prop('disabled' , true); $("#please_wait").show(); is supposed to be executed at the beginning of the function but is executed after the ajax call – user2942945 May 31 '17 at 19:32
  • could you paste your ajax call as well? It sounds like the async false requests are holding up the DOM reflow – Patrick Barr May 31 '17 at 19:38
  • You should not use `async: false`. See https://stackoverflow.com/questions/1151598/how-to-make-all-ajax-calls-sequential for how to make sequential AJAX calls. – Barmar May 31 '17 at 19:42

0 Answers0