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

Amrit Pandey
Amrit Pandey
17,595 Points

AJAX expert help me in this challenge!

What went wrong here?

weather.js
$(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());
});
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>What's the Weather Like?</title>
  <script src="jquery.js"></script>
  <script src="weather.js"></script>
</head>
<body>
  <div id="main">
    <h1>Current temperature: <span id="temperature"></span>&deg;</h1>
  </div>
</body>
</html>

1 Answer

Michael Liendo
Michael Liendo
15,326 Points

Looks solid. You're just missing the api key. They changed it a while ago so now you need one to get json back. Just sign up for one and add it as another key/value in your data object. The key is "appid" as seen in their sample call: http://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b1b15e88fa797225412429c1c50c122a1