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

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?