Using devbridge autocomplete and wunderground autocomplete API

I am trying to use the devoc autocomplete lib to download the wunderground.com autocomplete API and I continue to hold on. I attach cb to serviceUrl or not, it cannot parse the returned json. The response is prefixed with "{RESULTS: [{array data I want to use}]}.

When I use the autocomplete code provided in the docs, it says: "Unused syntaxError: Unexpected token:"

When I apply & cb = myresults to serviceUrl, I get the message "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 };
                })
            };
        }
    };
    a = $('#autoLocation').autocomplete(options);
});

API wunderground: http://www.wunderground.com/weather/api/d/docs?d=autocomplete-api devbridge git: https://github.com/devbridge/jQuery-Autocomplete wunderground: http://autocomplete.wunderground.com/aq?c=US&format=jsonp&cb=myresults&query=san%20f

, , - . .

+4
1

, , jquery jsonp default callaback query string key "cb", "callback". : jsonp: 'cb'

        that.currentRequest = $.ajax({
            url: serviceUrl,
            data: params,
            type: options.type,
            jsonp: 'cb',
            dataType: options.dataType
        }).done(function (data) {

:

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 };
                })
            };
        }
    };
    a = $('#autoLocation').autocomplete(options);
});

.

+8

Source: https://habr.com/ru/post/1536834/


All Articles