Undefined jQuery Autocomplete Results

So, I have the latest versions of jQuery and the user interface. I use the main autocomplete call and return a valid JSON (verified through JSONLint).

    $("input#cust_id").autocomplete({
        source: yoda.app.base + "/assets/cfc/util/autocomplete.cfc?method=cust",
        minLength: 2,
        select: function(event, ui) {
            log(ui.item ? ("Selected: " + ui.item.value + " aka " + ui.item.id) : "Nothing selected, input was " + this.value);
        }
    });

Both values ​​and label elements of the returned array appear in the list as undefined. I can see the results obtained through Firebug, and JSON is also correct there. Also, although only "undefined" is listed, he says that as many times as there are entries returned in JSON.

[{"VALUE":"custid1","LABEL":"My Customer Name 1"},{"VALUE":"custname2","LABEL":"My customer name 2"}]
+3
source share
1 answer

Your JSON should look like this:

[{value:"custid1",label:"My Customer Name 1"},{value:"custname2",label:"My customer name 2"}]

since keys are case sensitive:

var obj = {"hello" : "foo"};
alert(obj.HELLO); // undefined
alert(obj.hello); // foo
+5
source

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


All Articles