Difference between Synchronous and Asynchronous Ajax request

Synchronous ( async: false ) – Script stops and waits for the server to send back a reply before continuing. There are some situations where Synchronous Ajax is mandatory. In standard Web applications, the interaction between the customer and the server is synchronous. This means that one has to happen after the other. Synchronous part:

$.ajax({
         url: "file.php",
         type: "POST",
         async: false,
         success: function(data) {
                // write something awesome in response data part
         }
      });

Asynchronous Part:

$.ajax({
         url: "file.php",
         type: "POST",
         async: true,
         success: function(data) {
                // write something awesome in response data part
         }
      });

Thats it. Basically people use asynchronous when they need to send request on completion of first request. Means, your requests will work one by one not all request will send at once. Instead of it, in synchronous ajax calls your all requests will be done synchronously.

Leave a comment

Your email address will not be published. Required fields are marked *