Return Jquery data within Input

Asked

Viewed 220 times

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 own 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 function of seeking the customer:

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 doesn’t work... My question is:

How do I display the return data inside an input? Example: You will return me: Name, Phone, Email...

<input type="text" id="nome" value="">
<input type="text" id="telefone" value="">
<input type="text" id="email" value="">
  • What is the console output.log(date)?

2 answers

1

I think if you do something like $("#nome").val(data[nome]); works, but I’m not sure what the return of its function is.

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 according to the formatting of which vc returned the data in ajax.

  • It didn’t work out that way... But I returned otherwise, the return comes via array, but I now used json_encode to return and in jquery I used data = JSON.parse(data);, so it works

  • Show @Andrébaill I hope I helped. abç

Browser other questions tagged

You are not signed in. Login or sign up in order to post.