I would like to ask question related to fetching. I'm required to create a weather website. For this, firstly, I registered in weather api, got a key, and formulated my 'url' by following api doc. Now, the url itself seems works; 'https://api.openweathermap.org/data/2.5/weather?q=London&units=metric&appid=01d9f2d66b5fb9c863aa86b5cb001cd2', because the details are shown when paste in browser. The problem itself is that, when I use 'url' in my code with 'fetch', the api doesn't provide any info. the code is the following:
let weather = {
fetchWeather : function() {
fetch("https://api.openweathermap.org/data/2.5/weather?q=London&units=metric&appid=01d9f2d66b5fb9c863aa86b5cb001cd2")
.then((response) => response.json())
.then((data) => console.log(data));
},
};
the result:
VM1176:3 GET https://api.openweathermap.org/data/2.5/weather?q=London&units=metric&appid=01d9f2d66b5fb9c863aa86b5cb001cd2 net::ERR_FAILED
fetchWeather @ VM1176:3
(anonymous) @ VM1217:1
VM1176:3 Uncaught (in promise) TypeError: Failed to fetch
at Object.fetchWeather (<anonymous>:3:9)
at <anonymous>:1:9
could you pls help me how to solve the problem?
I want to know why the problem occurs and how to solve it