Waiting for an AJAX response

The default behavior of jQuery AJAX requests is that they run asynchronously, which means that you can run many AJAX requests or other JavaScript processes at the same time. If you call the $.ajax() function with the default settings, any JavaScript code after this AJAX request will be executed without waiting for a response. In most cases, this is the desired behavior, but there are some situations where you will want to prevent further execution until there has been a response to the AJAX call. This may be because you require some information from the first AJAX call to make a second, or just that your application requires data from the first call before it can run the second. There are a few ways to achieve this; ...

Get jQuery 2.0 Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.