Answer the question
In order to leave comments, you need to log in
How to get data from the server and write code?
Hello, I want to write a site for the weather, please tell me how to get the data and write the code correctly.
I thought to write all the logic inside, but in my opinion it looks somehow strange, and I can’t get the data with fetch from the outside
fetch('https://api.openweathermap.org/data/2.5/onecall?lat=51.5072&lon=-0.127551&lang=ru&exclude=hourly&appid=b712b6d2a4e3a7705a5a6d14a72bff46')
.then(function (resp) { return resp.json() })
.then(function (data) {
console.log(data)
// Всю логику думал написать сюда, но может это можно реализовать как-то по другому?
})
.catch(function () {
});
Answer the question
In order to leave comments, you need to log in
Yes, logic should be written in then. You can move this into a separate function, which you can then call in then.
It is also possible without then, but you need to use async-await
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question