首页 > 解决方案 > jQuery AJAX 队列没有得到响应

问题描述

我有一个数组,里面有 100 个项目,每个项目都应该发出一个 ajax 请求问题是服务器停止了 DDosAttack 所以我应该在队列中提出请求,但我不知道为什么在所有请求之前我的响应都是空的已经完成了。

array.map((row, index, arr)=> {
              return $.ajax({
                type: 'post',
                async: false, // this caused the problem
                url: 'url',
                data: {...},
                success: function(data){  
                  console.log(data) //  appears only when all the requests is done
                },
                error: function(data){
                   console.log(data) //  appears only when all the requests is done
                }
              })

          })

标签: javascriptjqueryajaxqueue

解决方案


我已经使用ajaxq了存储库,它非常有用

https://code.google.com/archive/p/jquery-ajaxq/downloads

array.map((row, index, arr)=> {
              return $.ajaxq('queue',{
                type: 'post',
                url: 'url',
                data: {...},
                success: function(data){  
                  console.log(data) //  appears only when all the requests is done
                },
                error: function(data){
                   console.log(data) //  appears only when all the requests is done
                }
              })

          })

推荐阅读