Return Jquery data inside Input

0

I have the following HTML

<select id="id_cliente">
    <option value="1">CLIENTE 1</option>
    <option value="2">CLIENTE 2</option>
    <option value="3">CLIENTE 3</option>
</select>

I have the following jQuery:

$("#id_cliente").change(function(){
    var id_cliente = $("#id_cliente").val();

    $.ajax({
        type: "POST",
        url: "contrato/buscar_cliente",
        data: {id_cliente:id_cliente},
        success: function(data){
            $("#nome").data[nome];
            $("#telefone").data[telefone];
            $("#email").data[email];
            alert(data);
        }   
    });     
});

And the search function for the client:

public function buscar_cliente(){
    $this->db->where("id_cliente", $_POST['id_cliente']);
    print_r($this->db->get("clientes")->row());
}

I know the way I did, it does not work ... My question is:

How do I display the return data within an input? Example: Will return: Name, Phone, Email ...

<input type="text" id="nome" value="">
<input type="text" id="telefone" value="">
<input type="text" id="email" value="">
    
asked by anonymous 22.05.2017 / 20:25

2 answers

1
$("#nome").data[nome];
$("#telefone").data[telefone];
$("#email").data[email];

replace with:

$("#nome").val(data.nome);
$("#telefone").val(data.telefone);
$("#email").val(data.email);

The code may vary depending on the formatting from which you returned the data in ajax.

    
22.05.2017 / 20:35
1

I think that if you do something like $("#nome").val(data[nome]); it works, but I'm not sure how your function returns.

    
22.05.2017 / 20:34