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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.