我有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()是完全做得到。