Uncaught (in promise) SyntaxError: Unexpected end of JSON input. Прошу вашей помощи)
Вылезает эта ошибка. Не понимаю в чем проблема. Надеюсь на вашу помощь)
window.addEventListener("load", () => {
let weatherDescription = document.querySelector(".weather-description");
let temperatureDegree = document.querySelector(".temperature-degree");
let locationCity_name = document.querySelector(".location-city");
let temperatureSection = document.querySelector(".degree-section");
const temperatureSpan = document.querySelector(".degree-section span");
let city = document.querySelector("input");
const api = `https://api.weatherbit.io/v2.0/current?city=${city}&key=24318d7f9afb4d84b552f00f75c8a711`.trim();
city.addEventListener("keyup", (enter) => {
if (enter.keyCode === 13) {
fetch(api)
.then((response) => {
return response.json();
})
.then((data) => {
const { app_temp, city_name } = data.data[0];
const { description, icon } = data.data[0].weather;
// Set DOM Elements from the API
temperatureDegree.textContent = app_temp;
weatherDescription.textContent = description;
locationCity_name.textContent = city_name;
// Formula for farenheit
let farenheit = (9 / 5) * app_temp + 32;
//Change temp to Cel/Faren
temperatureSection.addEventListener("click", () => {
if (temperatureSpan.textContent === "C") {
temperatureSpan.textContent = "F";
temperatureDegree.textContent = Math.floor(farenheit);
} else {
temperatureSpan.textContent = "C";
temperatureDegree.textContent = app_temp;
}
});
});
}
});
});
Ответы (1 шт):
Автор решения: Ein
→ Ссылка
Нужно смотреть что приходит в ответ. Ошибка говорит о том, что JSON не ожиданно закончился. Аналогичную ошибку можно получить сделав так: JSON.parse('{"foo":"ba')