Nhìn vào bài đăng này và câu trả lời ... https://stackoverflow.com/a/13090589/999958
Một hữu ích workaround cho tôi: Nhìn vào ajaxCallComplete() gọi trong mỗi .complete (...);
$(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(); });
};
Hy vọng có thể giúp ...
LIÊN QUAN: [Chờ nhiều cuộc gọi không đồng bộ để hoàn thành trước khi tiếp tục] (http://stackoverflow.com/question s/2768293/chờ-trên-nhiều-không đồng bộ-cuộc gọi-để-đầy-trước-tiếp tục) –