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.

lucasdc
  • 1,032
  • 2
  • 20
  • 42

1 Answers1

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..........
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188