If you're talking about this:
$.ajax({...});
someFunction();
where someFunction()
won't occur until the AJAX call completes then you have three options:
- Make the AJAX call
async: false
. Don't do this. It'll make your page unresponsive;
- Put
someFunction()
in the complete/success/error callbacks of the AJAX call. This is the recommended approach; or
- Use aplugin to manage a request queue eg Ajax Queue.
The first A in AJAX stands for "asynchronous". You just need to get used to the fact that these calls are asynchronous and stop trying to force a synchronous programming model on top of them. Adapt to the new programming model.