欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

AJAX——AJAX请求递归

发布时间:2024/10/5 编程问答 39 豆豆
生活随笔 收集整理的这篇文章主要介绍了 AJAX——AJAX请求递归 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

问题描述

需要发送同一个请求,但是AJAX异步机制的存在,在for/while/do..while使用AJAX会出现问题。

问题分析

封装函数,递归调用

解决方案

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

总结

以上是生活随笔为你收集整理的AJAX——AJAX请求递归的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。