JavaScript之循环请求数据获取发送AjaxasyncawaitPromisethenrandomtoStringsplitresolvereject
Posted web半晨
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript之循环请求数据获取发送AjaxasyncawaitPromisethenrandomtoStringsplitresolvereject相关的知识,希望对你有一定的参考价值。
async function circularRequest()
let list = [
id: 1, code: "15289682517" ,
id: 2, code: "15289682516" ,
id: 3, code: "15289682515" ,
];
for (let i = 0; i < list.length; i++)
await getJurisdiction(list[i].code).then((result) =>
let code, data = result;
if (code === 200) list[i].jurisdiction = data;
);
console.log("list:", list);
// list: (3) […, …, …]
// 模拟后端返回数据
function getJurisdiction(code)
return new Promise((resolve, reject) =>
let data =
code: 200,
message: "操作成功",
data: null,
;
if (code)
data.data = Math.random().toString().split(".")[1];
return resolve(data);
else
data.code = 500;
data.message = "操作失败";
return reject(data);
);
circularRequest();
以上是关于JavaScript之循环请求数据获取发送AjaxasyncawaitPromisethenrandomtoStringsplitresolvereject的主要内容,如果未能解决你的问题,请参考以下文章