async function getTitle(url) {
let response = await fetch(url);
let html = await response.text();
return html.match(/<title>([\s\S]+)<\/title>/i)[1];
}
for(let i=0;i<2;i++){
let urls = `https://tc39.github.io/ecma262/`
!async function(){
let result = await getTitle(urls).then(function(title){
console.log('22222',title,i)
return title
})
console.log(result)
}()
}```
实际运行结果是,同时发生了两个请求,然后等待请求接过返回后,打印结果
![clipboard.png](/img/bVbdCHI)
想期望是请求完第一个接口,并且成功返回后,再请求第二个接口请求
慕田峪9158850
相关分类