Thursday, May 14, 2020

What is synchronous and Asynchronous call?

Ans:-
Ajax:- It is a technique that incorporates a client-side script (i.e. a script that runs in a user's browser) that communicates with a web server. An AJAX application might use XML to send data, it could also use just plain text or JSON text. 
By default, the$.ajaxrequest in jQuery is set to asynchronous. The variable name is async and the value is set to true

Synchronous ( async: false ) – In case of Synchronous AJAX request, the request is sent to the server and the client waits for the server’s response before it executes the script further. So this is the special case when the further script is dependent on the results returned by the server.

Asynchronous ( async: true ) - In an Asynchronous request the process is handled independently and is not dependent on following processes. So that the script do not wait for the server request to complete before executing the remaining lines of code. As soon as the server response is completed it is sent back to the client.

$.ajax({
         url: <siteUrl>,
         type: "POST",
         async: false,
         success: function(data) {
                // .....
         }
      });

No comments:

Post a Comment