Asynchronous and Synchronous request jQuery
When working is single page applications or on page operation without refreshing them on any event. Developer mostly use jQuery for smooth development. It will allow us Synchronous & Asynchronous request to fetch information from server or from any API.
Mostly developer used Asynchronous request but some time we have to load data first and then start processing on that data before provide end results. In Asynchronous we can't get this feature.
Like if we have A as Asynchronous and there are two more Asynchronous request inside the A then inner two Asynchronous request will execute parallel and may be one of them completed before other one. But in Synchronous if the first request is not completed the next one can't be start it's execution it is somehow dependency on other block of JavaScript.
Synchronous: A synchronous request blocks the client until it has completed the operation. In this case, the browser's javascript engine is blocked.
By default jQuery is not providing synchronous request, so we have to implicitly define synchronous request using $.ajax().
$.ajax({
type: "GET",
url: web_url,
async: false
})
In the above code you can observe we are declaring false for the async parameter. Which will request in Synchronous.
Asynchronous: A request asynchronous does not block the client, i.e. The browser reacts. Users can also perform other operations at that time. In this case, the browser's javascript engine is not blocked.
Note: By default all ajax & jQuery request have "async:true".