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 = '';
  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
Brendan Whiting
Front End Web Development Techdegree Graduate 84,615 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!