Just wondering before I start hacking away with my code. For example:
if (blahblah) {
$.ajax("randomthingy1");
}
if (blahblahblah) {
$.ajax("randomthingy2");
}
// Use jQuery to test when they've both finished. Obviously they won't always both finish, as they might not both exist, and none of them might exist either.
$.when($.ajax("randomthingy1"), $.ajax("randomthingy2"), function (stuff) {
// foo
}
// Might produce an error, as one might not exist. But will it move on and not bother?
Just wondering. And if it does bother to create an error and stop execution, is there a way to catch the error and continue?
.when()will only fire thedone() handlerif all Defered objects you passed in could get resolved. So in your instance, if one Ajax request fails for whatever reason, the mixed in Defered object will resolve to fail and your handlers bound through.when() -> donewill not fire. But of course all your handlers bound tofailoralwayswill fire in that case.See http://api.jquery.com/category/deferred-object/