un'occhiata a questo post e risposte ... https://stackoverflow.com/a/13090589/999958
Un utile soluzione per me: Guarda una chiamata ajaxCallComplete() in ogni .plete (...);
$(document).ready(function(){
loadPersons();
loadCountries();
loadCities();
});
// Define how many Ajax calls must be done
var ajaxCalls = 3;
var counter = 0;
var ajaxCallComplete = function() {
counter++;
if(counter >= ajaxCalls) {
// When all ajax calls has been done
// Do something like hide waiting images, or any else function call
$('*').css('cursor', 'auto');
}
};
var loadPersons = function() {
// Show waiting image, or something else
$('*').css('cursor', 'wait');
var url = global.ctx + '/loadPersons';
$.getJSON(url, function(data) {
// Fun things
})
.complete(function() { ajaxCallComplete(); });
};
var loadCountries = function() {
// Do things
var url = global.ctx + '/loadCountries';
$.getJSON(url, function(data) {
// Travels
})
.complete(function() { ajaxCallComplete(); });
};
var loadCities = function() {
// Do things
var url = global.ctx + '/loadCities';
$.getJSON(url, function(data) {
// Travels
})
.complete(function() { ajaxCallComplete(); });
};
La speranza può aiutare ...
CORRELATI: [In attesa di più chiamate asincrone da completare prima di continuare] (http://stackoverflow.com/question s/2768293/attesa-su-più-asincrone-chiamate-a-completa-prima-continua) –