Hello, World!
I’m having issues with my weather app ( https://codepen.io/aviage-01/pen/RyOGWg) ). At the moment, I am trying to get the image to work. I have to code to retrieve the JSON, and then I alert that. However, nearly every time I alert the JSON, I get a different response. I am calling the alert directly after the JSON is returned, so I don’t think it’s an asynchronous loading issue. Here’s the code:
var lat = 0;
var lon = 0;
var weatherData = {};
$(".holding-box").hide();
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
lat = position.coords.latitude;
lon = position.coords.longitude;
$.getJSON(
"https://fcc-weather-api.glitch.me/api/current?lon=" +
lon +
"&lat=" +
lat,
function(json) {
$(".weather-description").html("");
$(".weather-image").attr("src", JSON.stringify(json.weather[0].icon))
alert(JSON.stringify(json.weather[0].icon)+ " and " + $(".weather-image").attr("src"))
}
);
});
}
@Whoever fixed the post’s appearance, thanks very much!