loadInfo: function(){
var jsonCounter = 0,
room = ['room1','room2','room3'],
dates = [],
prices = []
$.each(booking.rooms, function(key, room_name) {
$.getJSON('/get_info.php?room='+room_name, function(data) {
dates[room_name] = data
jsonCounter++
})
$.getJSON('/get_info.php?room='+room_name+'&prices', function(data) {
prices[room_name] = data
jsonCounter++
})
})
function checkIfReady() {
if (jsonCounter === rooms.length * 2) {
clearInterval(timer)
run_the_rest_of_the_app()
}
}
var timer = setInterval(checkIfReady, 100)
}
(Modificata molto, in quanto è parte di una classe ecc ecc)Firing richiamata dopo molteplici richieste Ajax sono completi
Al momento questo si sente un po 'hacker, come l'uso del timer sembra spazzatura. Vorrei usare $ .when e $ .done, ma non so quante stanze ci potrebbero essere, quindi non so cosa mettere quando.
Come faccio a garantire che run_the_rest_of_the_app() venga chiamato solo una volta che tutte le richieste AJAX vengono restituite?
+1 molto elegante –