[Solved-6 Solutions] jQuery to perform a synchronous, rather than asynchronous, Ajax request - javascript tutorial
Problem:
How to get jQuery to perform a synchronous, rather than asynchronous, Ajax request ?
Solution 1:
To implement a synchronous request, change the third parameter in the open () method to false:
async = false are used for quick testing. You will also find synchronous requests in older JavaScript code. Since the code will wait for server completion, there is no need for an onreadystatechange function:
Synchronous XMLHttpRequest (async = false) is not suggested because the JavaScript will stop executing until the server response is ready. If the server is busy or slow, the application will suspend or stop.
Solution 2:
Solution 3:
Solution 4:
We can set the jQuery's Ajax setup in synchronous mode by calling
and then perform your Ajax calls using jQuery.get( ... ); then just turning it on again once
It might be useful to somebody that does want to reconfigure their jQuery.get()
or jQuery.post()
to the additional elaborate jQuery.ajax()
syntax.