I use $.when
to call an ajax function in a loop:
for ( var i = 0; i < 4; i++ ){
$.when(get_total_price("var1","var2")).then(function (v) {
console.log("i= "+i);
});
}
I expect that in every iteration, it waits for the ajax call to be completed, than the next iteration is executed, so the result of this simple example will be:
i= 1
i= 2
i= 3
but the result is:
i= 5
i= 5
i= 5
In this case I can't use the i
inside the ajax call!