Pass variable to jqueryui autocomplete

0

I want to pass a variable of a text type input to jQueryui autocomplete, but I think I have the wrong syntax or maybe it can not be done.

The code I have is this:

$('#InPedido_DirEnvio').autocomplete({
        source:'./Scripts/Phps/Autocompletar.php?pag=autocompletar_dir_clientes&cli='+$('input[name=InPedido_idcliente]').val(),
        minLength:3,
        dataType: "json",

the value of the input as you can see what I'm going through with $('input[name=InPedido_idcliente]').val() but I do not know if it is possible to pass it in source, I have bad syntax or I have to do it in another way.

is this possible?

    
asked by Killpe 12.06.2017 в 13:32
source

1 answer

1

For these cases you have to generate your own source function by calling within it the source of truth.

$("#InPedido_DirEnvio").autocomplete({
  source: function(request, response) {
    $.ajax({
        url: "/Scripts/Phps/Autocompletar.php?pag=autocompletar_dir_clientes&cli="+$('input[name=InPedido_idcliente]').val(),
        success: function(data) {
            response(data);
        }
    });
  },
  minLength: 3
});

Here you can see more ways to solve it.

    
answered by 12.06.2017 / 14:08
source