我有这样的数组urls = ['url1','url2','url3'];
我该如何跟踪数组索引,所以每个Ajax
调用我可以删除一个元素。如何在ajax调用期间跟踪数组索引
这里是什么我想
var my_delay = 2000;
var urls = ['url1','url2','url3'];
$(function() {
callAjax();
});
function callAjax() {
/*$.ajax({
// my ajax params ..............
success: function(data){
\t \t if(urls.length != 0){
console.log('must be called only 3 times');
\t \t setTimeout(callAjax, my_delay);
urls.shift();
\t \t }
}
}); */
console.log('must be called only 3 times');
console.log('in real situation i will going to use above commented ajax code');
if(urls.length != 0){ // stop here but you are not stoppping why?
setTimeout(callAjax, my_delay);
urls.shift();
} // end of if
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
问:我想停止Ajax调用时存在urls[]
没有元素请记住ajax
打算请在该场景中拨打php page
我也想跟踪array index
究竟是什么你想在这里实现吗?你是不是想调用相同ajax调用3个单独的url?为什么你不只是遍历'urls',并在该循环中执行ajax调用? – Cerbrus
我看到你没有达到你的教程中有关javascript的循环部分 – madalinivascu
@Cerbrus什么循环,我没有看到任何循环? – madalinivascu