Select Loading without AJAX data

Asked

Viewed 21 times

0

I have ajax, which is coming with the blank data, as you can see in the images below, this arriving the data, except that at the time of loading in select, the value, and text, are empty

<script>
    $("#UF").on("change", function() {
       
        var url = '@Url.Action("BuscaCidades", "CidadeG", new {area = "Gerencial"})';
        var estado = $("#UF option:selected").val();
        debugger;
        $.ajax({
            type: 'GET',
            data: { estado: estado },
            url: url,
            dataType: 'json',
            success: function (cidade) {
                debugger;
                if (cidade != null) {
                    var selectbox = $('#cbmunicipio');
                    $("#cbmunicipio").empty();
                    $('<option>').val("0").text("Selecione o Município").appendTo(selectbox);
                    $.each(cidade.cidade,
                        function(i, d) {
                            $('<option>').val(d.id).text(d.value).appendTo(selectbox);
                        });


                }
            },
            error: function(ex) {
                //alert('Failed to retrieve states.' + ex);
            }
        });
    })
</script>
   <select id="cbmunicipio" class="form-control">
                                               
    </select>
inserir a descrição da imagem aqui inserir a descrição da imagem aqui inserir a descrição da imagem aqui

  • What is the structure of this object you receive through AJAX? Your select seems to have several options, these options are only blank. Make sure that the names of the cities are in d.value?

  • I’m going for one more image.. Just a moment... I don’t know much about ajax, I was basing myself on this question here question

  • 2

    The estate Value begins with a capital v, replace d.value for d.Value. Do the same with Id.

  • Putz... that’s all it was!!!!!!

  • puts as an answer, I accept as correct!

  • This is just a typo, if I’m not mistaken these questions are usually closed, since it will hardly serve as a reference to another user.

Show 1 more comment
No answers

Browser other questions tagged

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