我有一个数组,里面有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
}
})
})
答案 0 :(得分:0)
我使用过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
}
})
})