How to handle the JSON response with JavaScript

1
<script type="text/javascript">
$(function($) {
    $('#enviaadv').submit(function() {
        //document.getElementById('btnConsultar').disabled = true; 
        $('div.mensagem-erro').html('');

        $(this).ajaxSubmit(function(resposta) {

            if (!resposta){
                $onclick = showadv('bottom','left',resposta);
            }
            else
            {
                $onclick = showadv('bottom','left',resposta);           
            }

        });

        return false;

    });
});
</script>   

I'm getting JSON data in resposta like this:

{"adv_nome":"Gabriel","adv_id":"8c7dac3ea415b863c8c8789b6667b2b1"}

How can I handle this data to get adv_nome and adv_id ?

    
asked by anonymous 18.06.2018 / 19:35

1 answer

1

You can access the object values Json just use the (.) For more examples: link

var resposta = {"adv_nome":"Gabriel","adv_id":"8c7dac3ea415b863c8c8789b6667b2b1"};
var x = resposta.adv_nome;
document.getElementById("demo").innerHTML = x;
<p id="demo"></p>
    
18.06.2018 / 19:41