Это мой первый раз, когда я использую API. У меня есть следующий код Javasript, который я нашел из учебника, но я не уверен, как отобразить его в HTML. Я пытаюсь получить доступ к API Weatherbit Current Weather. < /P>
//WeatherBit API URL and Key
const apiKey = 'gonna leave this out';
const apiUrl = `https://api.weatherbit.io/v2.0/current? ... ude=alerts`;
const requestOptions = {
method: 'GET',
},
};
//For HTML Output
const outputElement = document.getElementById('output');
//GET request
fetch(apiUrl)
.then(response => {
if (!response.ok) {
if (response.status === 404) {
throw new Error('Data not found (404)');
} else if (response.status === 500) {
throw new Error('Server Error (500)')
} else {
throw new Error('Network response was not ok');
}
})
return response.json()
};
})
.then(data => {
//display in HTML
outputElement.textContent = JSON.stringify(data, null, 2);
})
.catch(error => {
console.error('Error:', error);
});
< /code>
и в HTML у меня есть: < /p>
Loading Weather Data...
Подробнее здесь: https://stackoverflow.com/questions/797 ... ta-in-html