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 trialJason Larkin
13,970 PointsjQuery and APIs: Call the jQuery $.getJSON method problem
Help! - I'm trying to do the following: You've specified the URL, a data object, and a callback function. Use jQuery's $.getJSON() method to make the AJAX call. It's not working and I'm taking it straight from the Workspace notes. Can anyone please help?
$(document).ready(function() {
var weatherAPI = 'http://api.openweathermap.org/data/2.5/weather';
var data = {
q : "Portland,OR",
units : "metric"
};
function showWeather(weatherReport) {
$('#temperature').text(weatherReport.main.temp);
}
$.getJSON(weatherAPI, data, showWeather);
});
});
2 Answers
Nicholas Klunder
8,144 PointsLooks like you have an extra closing bracket at the end. Remove the last }); and it should work.
Giovanni Dalla Rizza
10,637 PointsWhy in the getJSON() method you can declare the showWeather() function without the brackets? Is it a privilege of jQuery? In the same challange I had put the function inside a var, but it didn't work :(
Jason Larkin
13,970 PointsJason Larkin
13,970 PointsThanks, I knew it was something simple!