jquery - Using devbridge autocomplete and wunderground autocomplete API -
i'm attempting use devbridge jquery autocomplete lib pull wunderground.com's autocomplete api, , keep getting held up. whether attach cb serviceurl or not, can't parse returned json. response prefixed "{results: [{ array data want use }]}".
when use autocomplete code provided in docs, says "uncaught syntaxerror: unexpected token :"
when apply &cb=myresults serviceurl, "uncaught referenceerror: myresults not defined"
my code is:
var options, a; $(function(){ options = { serviceurl:'http://autocomplete.wunderground.com/aq?c=us&format=jsonp&cb=myresults', minchars: 7, datatype : "jsonp", transformresult: function(response) { response = json.parse(response); return { suggestions: $.map(response.mydata, function(dataitem) { return { value: dataitem.name, data: dataitem.zmw }; }) }; } }; = $('#autolocation').autocomplete(options); }); the wunderground api : http://www.wunderground.com/weather/api/d/docs?d=autocomplete-api devbridge autocomplete git : https://github.com/devbridge/jquery-autocomplete sample response wunderground : http://autocomplete.wunderground.com/aq?c=us&format=jsonp&cb=myresults&query=san%20f
i've been @ loss few days, , i'm sure i'm looking on extremely simple. or guidance appreciated.
to working need modify source because jquery jsonp default callaback query string key not "cb", "callback". in autocomplete source add: jsonp: 'cb'
that.currentrequest = $.ajax({ url: serviceurl, data: params, type: options.type, jsonp: 'cb', datatype: options.datatype }).done(function (data) { then code should be:
var options, a; $(function(){ options = { serviceurl:'http://autocomplete.wunderground.com/aq?c=us&format=jsonp', minchars: 2, datatype : "jsonp", transformresult: function(response) { console.log('response', response); return { suggestions: $.map(response.results, function(dataitem) { return { value: dataitem.name, data: dataitem.zmw }; }) }; } }; = $('#autolocation').autocomplete(options); }); this working fine me.
Comments
Post a Comment