javascript - 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
}
})
})
解决方案
我已经使用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
}
})
})
推荐阅读
- php - 未能创建 COM 对象“CrystalReports.ObjectFactory.2”:未注册类
- rule-engine - 如何在 Decision Manager 中导出和导入本地项目?
- asp.net - ASP.NET 的高 CPU 使用率
- azure-vm-scale-set - 具有应用程序网关和 Azure LB 的 Azure ScaleSet
- python - 列表理解在 python 中不起作用
- apache-spark - 运行 spark 应用程序不显示在 spark 历史服务器上
- vba - VBA 数据透视表;错误“1004”参考无效
- amazon-web-services - 如何使用 moto 配置 AWS Firehose(Python AWS 模拟库)
- python - 使用 cv2.imread() 时出现 Python openCV 错误
- hbase - 如何使 HBASE 持久化并在刷新前从 Memstore 获取通知