Jquery autocomplete plugin Can not read property 'length' of undefined

0

I am using this wonderful plugin developed by Devbridge. Using your examples one works well and the other does not:

The one that works:

// Obtengo listaDeProfesionales desde /profesionales/get_lista/
$('#autocompleteInput').autocomplete({
    lookup: listaDeProfesionales,
});

The one that does not work:

$('#autocompleteInput').autocomplete({
    serviceUrl: "/profesionales/get_lista/",
});

I get this error on the screen:

Uncaught TypeError: Cannot read property 'length' of undefined

In the plugin file

jquery.autocomplete-devbridge.js:792

I do not understand why, since it is the same source of information, only that one is stored locally and the other is via AJAX. /profesionales/get_lista/ returns a JSON in the {value: "..", data: any} format as requested by the plugin.

According to the documentation, the serviceURL parameter must provide the URL that returns a serviceUrl string. From what I see, I'm not really understanding what it's supposed to be.

    
asked by Genarito 02.03.2017 в 17:05
source

1 answer

1

There I found the problem, apparently the format of the JSON returned by the AJAX function has to be:

{
    suggestions: [
        { "value": "United Arab Emirates", "data": "AE" },
        { "value": "United Kingdom",       "data": "UK" },
        { "value": "United States",        "data": "US" }
    ]
}

And I was not incorporating the "suggestions" key.

More information here

    
answered by 02.03.2017 в 17:26