在 div Html 中显示 js 数据
Display js Data in div Html
我想在控制台日志中显示从这段代码中获得的数据(在 JSON 中)并将其显示在 HTML 中。我应该使用哪种方法?
async function getAVA() {
fetch('https://graphql.avascan.info', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `
query {
stats {
priceAvaxUsd
}
}`
}),
})
.then((res) => res.json())
.then((result) => console.log(result));
}
getAVA();
async function getAVA() {
fetch('https://graphql.avascan.info', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `query {stats {priceAvaxUsd}}`
}),
})
.then((res) => res.json())
.then((result) => {
console.log(result);
document.getElementById('result').innerHTML = result.data.stats.priceAvaxUsd;
})
.catch(error => {
console.log(error);
})
}
getAVA();
<div id="result"></div>
我想在控制台日志中显示从这段代码中获得的数据(在 JSON 中)并将其显示在 HTML 中。我应该使用哪种方法?
async function getAVA() {
fetch('https://graphql.avascan.info', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `
query {
stats {
priceAvaxUsd
}
}`
}),
})
.then((res) => res.json())
.then((result) => console.log(result));
}
getAVA();
async function getAVA() {
fetch('https://graphql.avascan.info', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `query {stats {priceAvaxUsd}}`
}),
})
.then((res) => res.json())
.then((result) => {
console.log(result);
document.getElementById('result').innerHTML = result.data.stats.priceAvaxUsd;
})
.catch(error => {
console.log(error);
})
}
getAVA();
<div id="result"></div>