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 AJAX Basics (retiring) AJAX and APIs Call the jQuery $.getJSON method

Jamie Bradley
Jamie Bradley
7,148 Points

AJAX GET method

I'm on stage four of AJAX and APIs and I've tried every variation of the function portion of the AJAX GET method and nothing works. I'm clearly writing something incorrectly, but I have no idea what. This is what I have:

$(document).ready(function() {

  var weatherAPI = 'http://api.openweathermap.org/data/2.5/weather/?jsoncallback=?';
  var data = {
    q : "Portland,OR",
    units : "metric"
  };

 function showWeather(weatherReport) {
    $('#temperature').text(weatherReport.main.temp);
  }

  $.getJSON(weatherAPI, data, showWeather);

});

1 Answer

Dave McFarland
STAFF
Dave McFarland
Treehouse Teacher

Hi Jamie Bradley

You don't need to add ?jsoncallback=? to the end of the openweathermap URL.

Jamie Bradley
Jamie Bradley
7,148 Points

Ha, no I did not :) Thank you!