我有2個問題:Javascript ajax循環執行
1-當ajax post執行很多次時如何設置延遲?
2 - 當變量exe_counter達到0時如何運行some_multi_ajax_function()?
這裏是我的代碼:
for (i = 0; i < some_data_list.length; i++) {
exe_counter=1;
data = some_data_list[i];
// Many ajax posts will be executed here. In the end exe_counter will be set to 0;
some_multi_ajax_function(data);
}
function some_multi_ajax_function(data){
$.ajax({
...
}.done(function(d) {
// here it could be used another ajax function
exe_counter = 0;
});
}
UPDATE
我很抱歉,我已經壞解釋。 我想執行
data = some_data_list[1]; // second iteration. after that and others
some_big_function(data); // this can't start if exe_counter != 0
時exe_counter == 0它意味着some_multi_ajax_function()是完全做得到。