javascript - Problems passing '?' in URL to ajax call -


i trying create ajax call weatherunderground. code is:

$(".city").autocomplete({     source: function( request, response ) {     $.ajax({         // 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 " + this.value);  },  open: function() {     $( ).removeclass( "ui-corner-all" ).addclass( "ui-corner-top" );  },  close: function() {    $( ).removeclass( "ui-corner-top" ).addclass( "ui-corner-all" );    }  }); 

no matter how treat question mark following aq 'uncaught syntaxerror: unexpected token :' error. if encode ? '?' &? in resulting url. if remove ampersand request functions correctly. if use either encodeurl() on entire string or encodeurlcomponent of ? results %3f doesn't work either.

i ready tear hair out, know do?

the error stems mismatched parameter name rather ? in url.

the parameter @ issue 1 specifies jsonp callback:

http://.../aq?query=san%20f&callback=jquery111___140___&ts=12345 //                          ^^^^^^^^ 

and, jquery's default name of callback isn't api expecting:

cb           jsonp callback method name 

to change parameter, can include jsonp: 'cb' in request options.

$.ajax({     url: "http://autocomplete.wunderground.com/aq?query=san%20f",     datatype: "jsonp",     jsonp: 'cb',      // ... }); 

example: http://jsfiddle.net/x2jea/


and, syntax error response. without cb parameter, service responding json, lacking "padding" make jsonp.

{"results": ...} //        ^ syntax error 
jquery111___140___({"results": ... }); // padding 

note jsonp javascript , requested <script> element. it's taking advantage of 2 languages' similarities in syntax. but, needs padding valid.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -