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

Uncaught TypeError: Illegal invocation jquery-1.11.3.min.js:5

So, i'm working on a weather app and I come into this error, it's an error in jquery some how?

Javascript Code:

$(document).ready( function () {
  var link = "http://api.ipinfodb.com/v3/ip-city/?callback=?";
  var options = {
    key : "",
    ip : myip,
    format : 'json'
  };
  function display(data) {
    var location = data.cityName;
    location += ',' + data.countryName;
  }
  $.getJSON(link, options, display);
  var tempUnit = '';
  $('button').click( function () {
    $('button').removeClass('active');
    $(this).addClass('active');
    if($(this).is(':contains("C")'))  {
      tempUnit = 'metric';
      doWeather();
    } else {
      tempUnit = 'imperial';
      doWeather();
    }
  });
  function doWeather() {
    var linkWeather = "http://api.openweathermap.org/data/2.5/weather?callback=?"
    var optionsWeather = {
      q : location,
      units : tempUnit
    }
    function displayWeather(data) {
      $('#main').html(data.main.temp);
    }
    $.getJSON(linkWeather, optionsWeather, displayWeather);
  }
  doWeather();
}); //end ready

3 Answers

I figured it out, it was actually the location (

    var optionsWeather = {
      q : location,
      units : tempUnit
    }

) wasn't loaded before it sent the GET request

Rick Hoekman
Rick Hoekman
9,494 Points

I haven't tested your code but at first glance it might be the question mark in the URL that is tripping it up. Can you test it if it will work when you replace the ? in the URL for the encoded %3F in the variables: link and the variable: linkWeather ?

Rick Hoekman
Rick Hoekman
9,494 Points

Oh good. You also clarified my own doubts if url's with parameters should need some special attention ;) Keep on learning and thanks for posting the question / solution! ;)