Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Jason Larkin
Jason Larkin
13,970 Points

jQuery 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
Nicholas Klunder
8,144 Points

Looks like you have an extra closing bracket at the end. Remove the last }); and it should work.

Jason Larkin
Jason Larkin
13,970 Points

Thanks, I knew it was something simple!

Giovanni Dalla Rizza
Giovanni Dalla Rizza
10,633 Points

Why 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 :(