Query just returns "undefined"--please help!

  • 1
  • Question
  • Updated 7 years ago
I wanted to dynamically create my query based on the city my user's in. This is basically a copy of the code sample for JQuery & JavaScript, except for the way the url is generated. When I run the code sample version, it works. When I run mine, I get "undefined" back.

Can anyone see an issue with this code? I've gone over it a ton and can't find anything wrong with it.

jQuery(document).ready(function ($) {

var urlQuery;
var urlBase;
var urlSubdivision;
var urlCity;

//Build the URL for the weather query.
switch (document.getElementById("MainContent_hdnCountry").value)
case 'Canada':
urlSubdivision = escape(document.getElementById("MainContent_hdnCountry").value + '/');
case 'USA':
urlSubdivision = escape(document.getElementById("MainContent_hdnSubdivision").value + '/');
urlBase = escape("http://api.wunderground.com/api/my_hidden_key/forecast10day/q/");
urlCity = escape(document.getElementById("MainContent_hdnCity").value + ".json");
urlQuery = (urlBase + urlSubdivision + urlCity);

url: unescape(urlQuery),
dataType: "jsonp",
success: function (parsed_json) {
// v-- This line is returning "undefined".
var location = parsed_json['location']['city'];
var temp_f = parsed_json['current_observation']['temp_c'];
alert("Current temperature in " + location + " is: " + temp_c);
Photo of ingrediential


  • 2 Posts
  • 0 Reply Likes
  • frustrated

Posted 7 years ago

  • 1
Photo of Brendan Hayes

Brendan Hayes, Official Rep

  • 962 Posts
  • 124 Reply Likes
when you try hitting the URL on the browser, does it work there, but just not in your code? You can use "autoip" to pick up the user's location.