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

Stephen Printup
seal-mask
.a{fill-rule:evenodd;}techdegree
Stephen Printup
UX Design Techdegree Student 45,252 Points

AJAX and APIs: Challenge Task 1, Sending AJAX request

Everything's in place to send the AJAX request: you've specified the URL, a data object, and a callback function. Use jQuery's $.getJSON() method to make the AJAX call.

This is what I have

$(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(
  "http://api.openweathermap.org/data/2.5/weather?jsoncallback=?",
    {
      format: "json"
    },
    function (data){

    }

  );
});

Thank you for any help

Here is a link to the video: http://teamtreehouse.com/library/ajax-basics/ajax-and-apis/making-the-ajax-request

2 Answers

Steven Byington
Steven Byington
13,584 Points

Here is what I have:

$(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);
});

You already have the three arguments set up for your $.getJSON request. You just need to pass them into the parenthesis for the method. Hope this helps.

Jamie Bradley
Jamie Bradley
7,148 Points

Are you certain this is correct? It looks right to me, but I have exactly this code and mine still returns an error :(

Steven Byington
Steven Byington
13,584 Points

I tried it again and it passed for me. What does it say when you error?