AJAX——AJAX请求递归
生活随笔
收集整理的這篇文章主要介紹了
AJAX——AJAX请求递归
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
問題描述
需要發(fā)送同一個(gè)請(qǐng)求,但是AJAX異步機(jī)制的存在,在for/while/do..while使用AJAX會(huì)出現(xiàn)問題。
問題分析
封裝函數(shù),遞歸調(diào)用
解決方案
currentIndex = 0; function getImg(){if(currentIndex>=items.length){ return;}var url = item[url];console.log(i);$.ajax({type: 'get',url: url,dataType: "json",async: false,cache: true,success: function(json){currentIndex++;console.log("test");var img = json.img;getImg();},error: function(data){console.log("error...");currentIndex++;getImg();}}); }參考文章
https://blog.csdn.net/chdyiboke/article/details/81914257
https://www.runoob.com/ajax/ajax-examples.html
https://blog.csdn.net/yuan882696yan/article/details/50296821
http://www.oschina.net/code/snippet_574558_13233
https://zhidao.baidu.com/question/245639610.html
總結(jié)
以上是生活随笔為你收集整理的AJAX——AJAX请求递归的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JavaScript——易班优课YOOC
- 下一篇: Web安全——易班优课YOOC课群在线测