【发布时间】:2016-03-01 11:55:45
【问题描述】:
我有一个类似的功能:
function callApi(url){
return fetch(url).then(response => {return response.json()}
).then(response => {return response})
}
function myFunction() {
var status = null;
while (status != "complete") {
setTimeout(function(){
callApi('myurl').then(response => {
status = response.status
}
}, 5000)
}
在这里我只是想检查我是否从 api 调用中获得了所需的状态。
直到我从我想要每 5 秒检查一次的 api 调用中获得所需的状态..
但这不起作用.. 我已经用谷歌搜索了,但没有根据我的需要理解解决方案。 如果有人能回答这个问题将非常有帮助。
我是 JavaScript 新手。我在某个地方看过es6 promise。
如果有人能解释一下,那就太好了..
谢谢
【问题讨论】:
-
你可以(并且应该)完全省略
.then(response => {return response}),行为不会改变一点
标签: javascript ecmascript-6 es6-promise