2

如何在 jQuery 自动完成中实现它?

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

    });
4

1 回答 1

2

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
                        }
                    }));
                }
于 2011-10-20T12:40:23.707 回答