【发布时间】:2021-10-26 18:50:48
【问题描述】:
我想从 api 获取数据(尤其是市值)并将其显示在我的 div 中。但是我的 html 没有显示任何关于执行的数据。我可能做错了什么?
<text id="result"></text>
<script>
// API for get requests
let fetchRes = fetch(
"https://api.lunarcrush.com/v2?data=assets&key=n8dyddsipg5611qg6bst9&symbol=AVAX");
// fetchRes is the promise to resolve
// it by using.then() method
fetchRes.then((res) => res.json())
.then((result) => {
console.log(result);
document.getElementById('result').innerHTML = result.config.data.0.market_cap;
})
.catch(error => {
console.log(error);
})
</script>
【问题讨论】:
标签: javascript json fetch fetch-api