So, I know of two methods to wait for an ajax request with jQuery:
$.ajaxSetup({async: false});
This method will make ajax synchronous. I do not want that.
The second method that I know of is the following:
$.post("foo.html", function (foo) {
// Put all the rest of the code in here
});
I do not want to do that either.
Is there a third option, which involves a handler which ‘listens’ for the ajax request to be completed, and then runs the rest of the code?
I thought there might be.
You could use Deferred objects in jQuery like this:
You can find more information about Deferred objects in the jQuery documentation: Deferred objects