Difficulties in loading data in Input via Ajax

1

I'm trying to load data via Ajax by typing a code and clicking on TAB it automatically searches the DB and prints it on form inputs.

Iranatestwithconsole.log(data)andthedataisbeingreturnedbutdoesnotloadtheInputsoftheform

FollowtheJSCode

//BuscoaChavedeAcesso$(document).ready(function(){$("#chave_acesso").change(function() {
        $.ajax({
            method: 'GET',
            headers: Alvo.header(),
            dataType: 'json',
            url:  "{{$urlApiSearchKey}}"+ this.value + "",



            success: function(data) {


                console.log(data);


                $('#obs_nota').val(data.obs_nota);
                $('#pedido').val(data.pedido);

                $('#tipo').val(data.tipo);


            },
            error: function() {
                alert("Código não encontrado!"); },

        });
    });
});
    
asked by anonymous 25.01.2018 / 16:39

1 answer

1

By the print posted in the question, the returned JSON is coming nested and the block data: is a subitem.

In this case, to get the values, you will have to use data 2x:

$('#obs_nota').val(data.data.obs_nota);
$('#pedido').val(data.data.pedido);
$('#tipo').val(data.data.tipo);

The 1st data of the Ajax return and the 2nd of the JSON subitem.

    
25.01.2018 / 17:08