【发布时间】:2020-05-03 01:24:45
【问题描述】:
我是 fetch api 的新手,我遇到了一个小问题。
document.getElementById('getText').addEventListener('click',function(){
fetch('text.txt')
.then(function(res){
return res.text
}).then(function(data){
document.body.innerHTML += `<br><br>${data}`
})
.catch(function(err){
console.log(err)
})
})
这是我的代码。它返回这个:
function text() { [native code] }
我希望它返回内容而不是这个。我不知道我该怎么办!?
抱歉问了一个愚蠢的问题。
谢谢
【问题讨论】:
-
.text是一个函数,不是普通的属性,你必须调用它
标签: javascript html promise fetch-api