Reputation: 1559
When someone enters my page, I want to load #portfolio
and #header
divs first on the page.
Then I want to start loading #slide
after the first 2 have finished loading (to improve functionality).
How can I do that using ajax/jquery?
Thanks a lot in advance!
Upvotes: 3
Views: 1705
Reputation: 237865
I presume you are using calls to $.ajax
to do the loading of #portfolio
and #header
.
From jQuery 1.5, you can use $.when
to perform an action when multiple AJAX requests have completed:
$.when(
$.ajax({
/* options to load #portfolio */
}),
$.ajax({
/* options to load #header */
})
).then(function() {
$.ajax({
/* options to load #slide */
});
});
Upvotes: 7
Reputation: 35832
You can nest ajax calls and get each next step on the success ajax call of the previous step.
$.ajax({ // Getting portfolio hear
success: function(){
$.ajax({ // Getting header here, on success callback of portfolio call
success: function(){
$.ajax({ // Getting slide here, on success callback of header
// So on,
});
}
});
}
});
Upvotes: 1