ajax - 发出多个同步ajax请求的最佳方法是什么
问题描述
我将 xlsx 转换为 json 并将这些行发送到后端处理的 ajax 请求。
excel 有 5k 行,我使用 concatMap 执行请求。还有另一种方法吗?我读过浏览器每个主机名最多有 6~12 个连接。
当我测试这个解决方案时,它在 6 分钟内执行了所有请求,每次使用 10 个请求。
浏览器真的每个主机最多有 6 个连接吗?
有人已经提出了相同的解决方案吗?
--
上面有一个我的解决方案的例子
let ids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let arrIds = this.chunkArray(ids, 3);
for(let i = 0; i < arrIds.length; i++) {
this.getSomethingFromAnAPI(arrIds[i]).subscribe(response => {
console.log(response.name)
this.data.push({
body: response.name,
title: response.name,
id: response.id
});
}, error => {
console.error(error);
});
}
//Send line to api
public getSomethingFromAnAPI(ids: number[]): any {
return from(ids).pipe(
concatMap(id => <Observable<any>> this.http.post('SEND_LINE_API'))
);
}
解决方案
推荐阅读
- javascript - Vis JS Edge:显示开始和结束的标签
- android - 如何使 TextView 可滑动并在其位置显示第二个 TextView
- firebase - Firebase Auth + Electron = 失败?
- angular - 与按钮一起使用的 mat-autocomplete(如 md-autocomplete)
- oracle - sql developer中的连接共享
- javascript - 使用路由器从独立子组件获取数据到其他组件
- haskell - 仅覆盖 Eq 实例实现中的少数数据案例
- javascript - 可以禁用 CMS 的冲突原生 JavaScript onSubmit 脚本吗?
- php - 如何在 ubuntu 17.10 中安装 php5.5
- android - 实现 URL 点击