Javascript 获取正文(response.text())返回空
代码:Javascript 获取正文(response.text())返回空,javascript,Javascript,代码: 我在做什么导致console.log(text)返回为未定义?您似乎希望返回response.text()的值到下一个。然后()块: var getURL = "someUrl.com" fetch(getURL) .then(response => { //console.log(response.status) //returns 200, confirms this works //console.log(response.text())
我在做什么导致
console.log(text)
返回为未定义?您似乎希望返回response.text()
的值到下一个。然后()
块:
var getURL = "someUrl.com"
fetch(getURL)
.then(response => {
//console.log(response.status)
//returns 200, confirms this works
//console.log(response.text())
//I can see the text being printed out in the console and its HTML
// I can also see a Promise is being fulfilled
response.text()
})
.then(text => {
console.log(text)
// this is returning as undefined
})
您可以在中了解有关使用承诺链接的更多信息。您需要返回response.text()
。这是否回答了您的问题?我认为这个问题是一个打字错误或重复的问题
fetch(getURL)
.then(response => {
return response.text()
})
.then(text => {
console.log(text)
})