I'm using AJAX to get some values from a server and I'm doing it asynchronously. How can I stop somehow to wait until the AJAX request ends? This is my code:
var response = {}
for (var i = 0; i < length; i++){
$.ajax({
url : url[i],
dataType : 'json'
}).success(function(result) {
processResult(result);
})
}
I figured I should create a function to wait, but it doesn't work properly:
function wait() {
for (var name in response) {
if (response[name] === undefined) {
setTimeout(function() {
wait()
},50)
}
}
processResult(); //this is function where I will process my AJAX result
}
Can anyone help me?