CreativeNotice
CreativeNotice

Reputation: 236

Undefined Results in jQuery Autocomplete

So I've got the latest versions of jQuery and UI running. I'm using the basic autocomplete invocation and returning valid JSON (validated via 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 the value and label elements of the returned array show up in the list as undefined. I can watch the results returned via Firebug and the JSON is correct there as well. Also, while the list only says "undefined" it does say that the same number of times as records returned in JSON.

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

Upvotes: 4

Views: 4377

Answers (1)

karim79
karim79

Reputation: 342635

Your JSON needs to look like this:

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

as keys are case sensitive:

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

Upvotes: 6

Related Questions