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

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,734 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!