我正在尝试从api响应中获取html。如果我执行以下提取请求:
const fetchHtml = () => {
return fetch('local:8080/api/getHtml')
.then((response) => {
console.log("Response:");
console.log(response.text());
})
.then((data) => {
console.log("Data:");
console.log(data);
});
};
};
我收到以下控制台消息:
Response:
Promise {<pending>}
__proto__: Promise
[[PromiseStatus]]: "resolved"
[[PromiseValue]]: "<html><head><title>Your interest in PROGRAM_NAME</ `Show 108 096 more Copy`"
Data:
undefined
如何从获取api请求中获得返回的html承诺值?谢谢。
发布于 2018-09-26 17:29:21
您必须从response.text返回.then
const fetchHtml = () => {
return fetch('local:8080/api/getHtml')
.then((response) => {
return response.text();
}).then((text) => {
console.log(text);
});
};
};
https://stackoverflow.com/questions/52523188
复制相似问题