Provides a way to execute callback functions based on one or more objects, usually Deferred objects that represent asynchronous events.
Execute a function after two ajax requests are successful. (See the jQuery.ajax() documentation for a complete description of success and error cases for an ajax request).
$.when($.ajax("/page1.php"), $.ajax("/page2.php")).done(function(a1, a2){
/* a1 and a2 are arguments resolved for the
page1 and page2 ajax requests, respectively */
var jqXHR = a1[2]; /* arguments are [ "success", statusText, jqXHR ] */
if ( /Whip It/.test(jqXHR.responseText) ) {
alert("First page has 'Whip It' somewhere.");
}
});
Execute the function myFunc when both ajax requests are successful, or myFailure if either one has an error.
$.when($.ajax("/page1.php"), $.ajax("/page2.php"))
.then(myFunc, myFailure);