链接a
.then
呼叫在你的例子中,如果你想要第二个
console.log
之后执行
showSearchResults
,你应该
return showSearchResults()
.然后
显示搜索结果
返回承诺;如果没有,您将希望将其包装在一个类似于您的
fetchStatus
类似地,如果您想链接
.然后
关闭a
setTimeout
,你可以这样写:
fetch(url, { method: 'post', etc... })
.then(fetchStatus)
.then(json)
.then(function(msg){
return new Promise(function(resolve, reject){
setTimeout(function() {
console.log("Next then fires after promise resolves");
resolve();
}, 4000)
})
})
.then(function(){
console.log("Second is firing")
})
.catch(err => console.log(error)) // always remember to catch errors!