【发布时间】:2019-04-11 13:28:44
【问题描述】:
我正在学习如何使用 fetch api,并且我正在尝试打印 Simpsons api 的报价作为练习。问题在于,答案一直是不确定的。你知道为什么它不只是打印报价吗?
let button = document.querySelector('#button')
let quote = document.querySelector('#quote')
function getInfoFetch(){
fetch('https://thesimpsonsquoteapi.glitch.me/quotes')
.then(response => response.json())
.then((data) => {
quote.innerText = data.quote;
})
.catch(err => console.log(err));
}
button.addEventListener('click', getInfoFetch)
【问题讨论】:
-
data[0].quote- 因为在这种情况下数据是一个数组 -
这应该是一个答案:P。
-
我做到了,然后我意识到只需 3 秒的调试时间就可以解决这样一个基本问题@zozo - 所以我删除了答案
标签: javascript ajax api fetch