jQuerybeast
jQuerybeast

Reputation: 14510

Wikipedia API Autocomplete with Json

How can I implement it in the jQuery Autocomplete?

    $("#searchForm input").autocomplete({
        source: function (request, response) {
            $.ajax({
                url: "http://en.wikipedia.org/w/api.php",
                dataType: "jsonp",
                data: {
                    maxRows: 10,
                },
            });
        },

    });

Upvotes: 2

Views: 1933

Answers (1)

Eonasdan
Eonasdan

Reputation: 7765

edit:

if you look at this example, you'll see a remote call with jsonp example

look at the source of their example and the sucess function. It looks like they are mapping the jsonp fields to use the data as needed for the autocomplete. use fiddler to see the json coming down from their example.

success: function( data ) {
 response( $.map( data.geonames, function( item ) {
                        return {
                            label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
                            value: item.name
                        }
                    }));
                }

Upvotes: 2

Related Questions