Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
alex gwartney
8,849 Pointsjson request not working
So im trying to get a json request from the open weather api example. But for some reason when i go to call the key value in the $.each method it says that the value for the key is undefined. Could you guys take a look at the code and see what it is im missing?
function getGs(data) {
console.log(data.main.humidity);
$.each(data.weather,function(i, weather) {
console.log(weather.main);
})
}
$(document).ready(function() {
var bggAPI = "http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139?";
$.ajax({
dataType: "json",
url: bggAPI,
success:getGs
});
});
3 Answers
alex gwartney
8,849 Pointsfunction getGs(data) {
console.log(data.main.humidity);
$.each(data.weather,function(i, weather) {
console.log(weather.main);
})
}
$(document).ready(function() {
var bggAPI = "http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139?";
$.ajax({
dataType: "json",
url: bggAPI,
success:getGs
});
});
Hayley Swimelar
7,124 PointsTry writing your success callback like this. So that the anonymous function passes data to your getGs function.
// Rest of your code.
success: function(data) {
getGs(data);
}
});
});
alex gwartney
8,849 PointsI figured it out i was miss reading the objects in json i had it all back word ill post the actual code here in a few