所有這些都是我第一次嘗試撰寫我的第一個 API fetch 并且我不斷收到以下錯誤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>
uj5u.com熱心網友回復:
看起來你有一個錯字const respone = await fetch(iss_url);應該是回應而不是回應。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/373513.html
上一篇:嘗試在MacM1上運行我的xamarin.formsios應用程式。當我打開任何包含帶有部分標題的TableView的頁面時崩潰
