为什么我从nasa的api中获取图片时,我的图片无法加载?[关闭]

问题描述 投票:0回答:1

当我尝试从NASA的api加载图像时,它无法加载,但它不会显示任何错误,所以我必须做什么来解决它。

fetch("https://api.nasa.gov/planetary/apod?api_key=JMlSbTcc8JLfEfCVfPhppl0KVBUp4U6M4nhzXMTl")
.then((resp) => resp.json())
.then((json) => {
    /*
    document.querySelector("#title").innerHTML = json.title;
    document.querySelector("#date").innerHTML = json.date;
    document.querySelector("#expl").innerHTML = json.explanation;
    document.querySelector("title").innerHTML = `Nasa Today | ${json.date}` 
    */
    document.querySelector("#spaceImg").innerHTML = `<img src="${json.hdurl}" style="height: 300px;">`
    console.log(json);
})
<div id="spaceImg"></div>
javascript json web dom
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.