Reputation: 896
I am using multiples ajax on page
1. $.load("abc.com/users");
2. $.load("abc.com/usersrates");
3. .....
4. .......
and there is one next button to go to another page which is disable now i want to enable this next button when all Ajax get completed.
Any Idea Will appreciated.
Upvotes: 0
Views: 56
Reputation: 358
edit: The $.when
responses in this are far better!
This is a bit hacky but will work
<script>
var totalLoads = 2;
var currentLoad = 0;
function checkLoads()
{
if (currentLoad == totalLoads)
{
// enable button
}
}
$.load("abc.com/users", funciton() { currentLoad++; checkLoads(); });
$.load("abc.com/usersrates", funciton() { currentLoad++; checkLoads(); }));
</script>
Upvotes: 0
Reputation: 749
Using $.when
.
$.when( $.ajax(...), $.ajax( ... ) ).done(function( a1, a2 ) {
}
}).failed(function(f1,f2){
});
// Each argument is an array with the following structure: [ data, statusText, jqXHR ]
// a1 and a2 are arguments resolved for the first and second ajax successful requests, respectively.
// f1 and f2 are arguments resolved for the first and second ajax failed requests, respectively.
Upvotes: 0
Reputation: 4870
Use $.when
, for multiple ajax call.
example:
$.when( $.load("abc.com/users"), $.load("abc.com/usersrates"))
.then( successCallback, errorCallback );
For more Info See This jQuery.when()
Upvotes: 1