json invalid label error using autocomplete.wunderground.com

  • 1
  • Question
  • Updated 6 years ago
How do I resolve the following error?

When using autocomplete.wunderground.com, my request returns json data but I get an invalid label error when parsing with jQuery.ajax(). Here is my code:

$('#citySearch').click(function() {
var QUERY = $("#searchName").val();
var citySearchUrl = "http://autocomplete.wunderground.com/..." + QUERY + "&format=JSONP";
alert(citySearchUrl);
$.ajax({
url: "http://autocomplete.wunderground.com/..." + QUERY + "&format=JSON&cb=",
dataType: "jsonp",
success: function(parsed_json) {
var city = parsed_json['name'];
document.write(""+name+"")
}
});

}
);

And here is the error:

invalid label:
{ "RESULTS": [

Thoughts?
Photo of thebadger2011

thebadger2011

  • 2 Posts
  • 0 Reply Likes

Posted 6 years ago

  • 1
Photo of thebadger2011

thebadger2011

  • 2 Posts
  • 0 Reply Likes
Fixed it like this:

$(document).ready(function() {

$('#citySearch').click(function() {
var QUERY = $("#searchName").val();
var searchCityUrl = 'http://autocomplete.wunderground.com/...;
$.ajax({
url: searchCityUrl,
dataType: 'jsonp',
cache: 'false',
success: function(data) {
for (i in data.RESULTS) {
var city = data.RESULTS[i]['name'];
$("#results").append(city+"
");
}
}
});
});
});