【发布时间】:2019-01-31 06:52:25
【问题描述】:
我正在使用 Fetch-node 获取服务。
const response = await fetch("MY URL", {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
timeout: 5000,
}).then(res => res.json()).then(json => console.log(json));
console.log(response);
然后我将结果记录在第二个console.log() 中,一切都很好。
但是,当涉及到第二个console.log() 时,响应是未定义的。
我需要的是在响应中存储的第二个记录。
我做的有什么问题吗?
【问题讨论】:
-
那么不要只记录,而是返回它......
-
@Andreas 你的意思是返回 json?
标签: javascript node.js ajax promise es6-promise