Hey, im having trouble fetching data from an API in my react weather app in codepen, meaning when i press the button to submit the city and get back the data it does nothing, like the fetchTheWeather function doesnt exist.im using the async/await method to fetch and its working fine through VSC localhost.
Anyway this is the link https://codepen.io/script3r/pen/MWgXmKd?editors=0010 , if someone has the time to take a look and give me some insight it would be great
Try logging each step. From getting values from fields to specific steps in program. From top of my head, this is simplest example:
$(document).ready(function(){
let city = "smederevo";
let country = "serbia";
let url = "http://api.openweathermap.org/data/2.5/weather?q="+city+","+country+"&appid=d42174afed4a1bb7fb19c043dee296b5";
$("button").click(function(){
$.ajax({
url: url,
async: true,
success: (data) => {
console.log(data);
},
error: (data)=>{
console.log(data);
}
});
});
});
Image of log:
i found the solution to that, you simply had to write https instead of http inside the fetch (). This is because “fetch” doesn’t work with HTTP anymore.