With jQuery I know that I can use $.when()
to wait for all of multipe Deferred
s to be resolved. (Or for the first one to be rejected.)
A quick and easy way would be to abort the other request when one of the two finishes, though you could also check the state of the deferred, the syntax of which will depend on your jQuery version which is why I go with abort for now.
function doStuff(data) {
alert( "Hello World!" );
}
var reqOne = $.post("foo.php"),
reqTwo = $.post("bar.php");
reqOne.done(function(data){
reqTwo.abort();
finished = true;
doStuff(data);
});
reqTwo.done(function(data){
reqOne.abort();
finished = true;
doStuff(data);
});