I am trying to create an Ajax call to weatherunderground. The code is:
$(".city").autocomplete({
source: function( request, response ) {
$.ajax({
// GET http://autocomplete.wunderground.com/aq?query=San%20F
url: "http://autocomplete.wunderground.com/aq?query=",
dataType: "jsonp",
data: {
featureClass: "P",
style: "full",
maxRows: 12,
name_startsWith: request.term
},
success: function( data ) {
response( $.map( data.RESULTS, function( item ) {
return {
label: item.name + item.countryName,
value: item.name
};
}));
}
});
},
minLength: 2,
select: function( event, ui ) {
log( ui.item ?
"Selected: " + ui.item.label :
"Nothing selected, input was " + this.value);
},
open: function() {
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
},
close: function() {
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
}
});
No matter how I treat the question mark following aq I get an 'Uncaught SyntaxError: Unexpected token :' error. If I encode the ? as '?' I get &? in the resulting URL. If I remove the ampersand the request functions correctly. If I use either encodeURL() on the entire string or encodeURLComponent of the ? the results are %3F which doesn't work either.
I am ready to tear my hair out, does anybody know what to do?