【发布时间】:2022-11-14 06:39:22
【问题描述】:
我目前正在开发一个项目,其中包括一个由 Django 构建和运行的网站。在这个网站上,我正在尝试通过快速 API 加载数据,并尝试通过 JavaScript 和 Fetch API 加载这些数据。但我总是得到一个 [object Promise] 而不是通过 API 提供的数据。我尝试了许多不同的方法,但似乎都没有奏效。
任何帮助将不胜感激!
我试过例如:
document.getElementById("1.1").innerHTML = fetch('the URL')
.then(response => response.text())
或者
document.getElementById("1.1").innerHTML = fetch('the URL')
.then(response => response.text())
.then((response) => {
console.log(response)
})
和许多其他方法。我也检查过,API 请求运行良好,返回一个字符串。
【问题讨论】:
标签: javascript html django fetch-api