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

Jake Goldstein
Jake Goldstein
1,304 Points

What is the issue with this getJSON request

Honestly for the life of me can't figure out what is wrong with this code and why I am getting an error. I defined the url, data, and the callback function and simply call getJSON with the params, still get a Bummer so can someone explain what I am doing wrong please

$(document).ready(function() {

  var weatherAPI = 'http://api.openweathermap.org/data/2.5/weather';
  var data = {
    q : "Portland,OR",
    units : "metric"
  function showWeather(weatherReport) {

  $.getJSON(weatherAPI, data, showWeather())
<!DOCTYPE html>
  <meta charset="utf-8">
  <title>What's the Weather Like?</title>
  <script src="jquery.js"></script>
  <script src="weather.js"></script>
  <div id="main">
    <h1>Current temperature: <span id="temperature"></span>&deg;</h1>

1 Answer

Brendan Whiting
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,703 Points

What you need to do is pass the reference to the function, but not call it:

$.getJSON(weatherAPI, data, showWeather) // no parens ()

The 3rd argument here needs to be a function, which will jQuery will call later, we're not calling it yet. It's the function that will be called when the response comes back.

Jake Goldstein
Jake Goldstein
1,304 Points

perfect, thanks man obvious mistake that I wont overlook now appreciate it!