【问题标题】:API Fetch not pulling dataAPI Fetch 不提取数据
【发布时间】:2022-01-11 08:33:34
【问题描述】:

所有这一切都是我第一次尝试编写我的第一个 API 提取,我不断收到以下错误 Uncaught (in promise) ReferenceError response is not defined at getISS (index.html:19) 这些是似乎导致问题的 2 行:

const data = await response.json();
getISS();

不完全确定如何解决此问题。

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    </head>
    <title> API Test </title>
    <body>
    
        <h1>Where is the ISS? </h1>
        
        <p>Latitude: <span id="lat"></span><br />
        Longitude: <span id="lon"></span>

        <script>
        const iss_url = 'https://api.wheretheiss.at/v1/satellites/25544';
        async function getISS() {
        const respone = await fetch(iss_url);
        **const data = await response.json();**
        const { latitude, longitude } = data;
            
        document.getElementById('lat').textContent = latitude;
        document.getElementById('lon').textContent = longitude;
        }
        
        **getISS();**
        
        </script>
    </body>
</html>

【问题讨论】:

  • 响应需要修复

标签: html json api


【解决方案1】:

您在 const respone = await fetch(iss_url); 处的拼写错误应该是响应而不是响应。

【讨论】:

    猜你喜欢
    • 2021-11-28
    • 2020-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多