How to get the Value result of Div divValor. result [2] in the mvc controller?

0
$(document).ready(function(){
        $("#btnSend").click(function(){
            $.ajax({
                url:'@Url.Action("VerificaCep","ConsultaCep")',
                type: "GET",
                contentType:"application/json",
                data: { cep: $("#txtCep").val() },
                success: function (result) {
                    $("#divValor").html("<label>Endereço:" + result[0] + "   Bairro:" + result[1] + "  Cidade:" + result[2] + "  Estado:" + result[3] + " </label>")
                },

                error: function(xhr, exception){
                    alert("Favor digitar o CEP!")
                }
            });

        });
        var Valor = document.getElementById('divValor.result[2]').innerHTML;
    });
    
asked by anonymous 09.09.2017 / 23:11

1 answer

0

2 errors: First that there is no div with id = divValor.result[2] , you are using label for all values. Second error result[n] must be inside function success: function (result)

var Valor;
$(document).ready(function(){
        $("#btnSend").click(function(){
            $.ajax({
                url:'@Url.Action("VerificaCep","ConsultaCep")',
                type: "GET",
                contentType:"application/json",
                data: { cep: $("#txtCep").val() },
                success: function (result) {
                    $("#divValor").html("<label>Endereço:" + result[0] + "   Bairro:" + result[1] + "  Cidade:" + result[2] + "  Estado:" + result[3] + " </label>");
                    valor = result[2];
                    console.log(valor);
                },

                error: function(xhr, exception){
                    alert("Favor digitar o CEP!")
                }
            });

        });

    });
    
11.09.2017 / 10:30