1

I'm trying to make an autocomplete using a json file but when I type on the input field, it shows nothing. I want to show only the data specified into "descricao", not into "codigo". Here is my code:

$(function() {
$('#autocompleteGrupo').autocomplete({
    source: function (request, response) {
        $.ajax({
            url: "jsonGrupo.jsp",
            dataType: 'json',
            data: request,
            success: function( data ) {
                response( $.map( data, function( item ) {
                    return {
                        label: value,
                        value: item.descricao
                    };
                }));
            }
        }); 
    },  
    minLength: 2
});
});

my json file:

[{"codigo":"1","descricao":"Tecnologia da Informação"}] 

Thanks,

Lucas.

1 Answer 1

1

Try the code shown below:


$(function() {
$('#autocompleteGrupo').autocomplete({
source: function (request, response) {
    $.ajax({
        url: "jsonGrupo.jsp",
        dataType: 'json',
        data: request,
        success: function( data ) {
            response( $.map( data, function( item ) {
                return(item.descricao)
            }));
        }
    }); 
   },  
   minLength: 2
  });
});


Also check that jquery ui js,css are included or not..........

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.