When to use async false and async true in ajax function in jquery

ajax, jquery

Solution

It's not relative to performance...

You set async to false, when you need that ajax request to be completed before the browser passes to other codes:

<script>
    // ...
    $.ajax(... async: false ...); // Hey browser! first complete this request, 
                                  // then go for other codes

    $.ajax(...); // Executed after the completion of the previous async:false request.
</script>

Problem

When to use use async false or async true in an ajax call. In terms of performance does it make any difference ? example : ``` $.ajax({ url : endpoint, type : "post", async : false, success : function(data) { if (i==1){ getMetricData(data)} else if (i==2) { capture = data; } } }); ```

Original source

Related problems