我有个问题,如果有人能帮我解决这个问题,我会非常感激。我是javascript新手,我向服务器发出http请求以获取一些数据,现在我想用html将数据显示到div中。我尝试使用createelement来显示我想在html中看到的文本和图像,但没有成功。有人能帮我吗?提前谢谢你的时间。
js代码
var displaySoccerApi = document.getElementById("socceApi");
const api_url =
"https://mysoccerapi.com";
// Defining async function
async function getapi(url) {
// Storing response
const response = await fetch(url);
// Storing data in form of JSON
var data = await response.json();
console.log(data);
// if (response) {
// console.log("data here");
// }
}
// Calling that async function
getapi(api_url);
html
<body>
<div id="soccerApi"></div>
</body>
我只想用api提供的图像和标题在html中显示从api到div的数据。有人能帮我吗?
当做
1条答案
按热度按时间b4wnujal1#
根据您的评论,假设返回的数据为以下形式:
简单的
forEach
环例如:一个工作片段,可能显示如何使用上述