i run the ajax request with async
set to false
inside the loop, and it stopped when the counter at 2. here is the script
var x = 0;
for(i=0; i<10; i++){
$.ajax({
async: false,
global: isGlobal,
type: 'POST',
url: url,
dataType: 'json',
data: JSON.stringify(body),
headers: {'Content-type':'application/json', 'Accept':'application/json'},
success: function(result){
x = result.something.value;
},
error: function(){
callback(false);
}
});
console.log(x); // debug x value
}
any idea why this is not working correctly?
PS: the url
is cross domain