2

I am trying to display jSON data in jQuery autocomplete, and everything works fine except the dropdown doesnt show up.
I could use parse: (for which there is a ton of examples) but i think i need the data to be displayed through source:.

is it possible to display data the way i am doing or do we need parse?
if yes, how?

Im not very good with jquery UI

$(function() {
    function log( message ) {
        $( "<div/>" ).text( message ).prependTo( "#log" );
        $( "#log" ).attr( "scrollTop", 0 );
    }

    $( "#aut_teachers" ).autocomplete({
        source: function(request, response) {
            $.ajax({
                url: base_url+"controller/model",
                data: request,
                dataType: "json",
                type: "post",
                success: function(data){
                    response(data.value);// here is where the problem is
                }

            });
        },
        minLength: 2,
        select: function( event, ui ) {
            log( ui.item ?
            "Selected: " + ui.item.value + " aka " + ui.item.id :
            "Nothing selected, input was " + this.value );
        }
    });
});
2
  • In jQuery, data is already your JSON object. I think you don't need to use data.value. Can you present a example of your JSON data? Commented May 8, 2012 at 20:30
  • yes, here: {"response":"true","message":[{"value":"Wren J Thomas","label":"1262"},{"value":"Wiseman Kim","label":"1257"},{"value":"Whitman","label":"1249"},{"value":"Whitehead Marcia","label":"1248"},{"value":"White Maja","label":"1247"}]} Commented May 8, 2012 at 20:32

1 Answer 1

2

You should use data.message as a parameter do response instead of data.value.

Since, data.message is a array of objects, and the objects are label/value, you can use it.

Check Autocomplete Docs for more information.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.