我有這樣的數組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