$.when()
$.when() waits for multiple Deferreds (or Promises) to complete. Its done callback fires when all succeed; fail fires when any fails.
$.when() waits for multiple Deferreds (or Promises) to complete. Its done callback fires when all succeed; fail fires when any fails.
$.when(
$.getJSON("/api/users"),
$.getJSON("/api/products"),
$.getJSON("/api/orders")
).done(function(users, products, orders) {
// All three completed
renderDashboard(users[0], products[0], orders[0]);
}).fail(function() {
console.error("One or more requests failed");
});
Each argument to the done callback is the response array from the corresponding request.