Jquery Autocomplete not showing results [closed]

2019-07-08 21:16发布

问题:

I have the following code:

var acOptions = {
             source:function (request, response) {
                 $.ajax({
                     url: "index.php?option=com_fmw&view=keywords_api&controller=keywords_api&format=raw", 
                     type: "GET", dataType: "json",
                     data: { expr: request.term},
                     sucess: function (data) {
                         response($.map(data, function (item) {
                             return item.value;
                         }))
                     }
                 })
                 }, 
     minChars: 1,
     dataType: 'json'
};

$( "#search_box_input" ).autocomplete(acOptions);

I get the following response from the server:

[{"value":"Greater"},{"value":"great"},{"value":"greatly"},{"value":"Greater-Axe"}]

However, the autocomplete field is not showing results, even though I can see that the ajax request got sent and that the server answered. What am I doing wrong?

回答1:

sucess is spelt wrong. Try success instead.

success: function (data) {
    response($.map(data, function (item) {
        return item.value;
    }))
}