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>
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 ind.value
?– Andre
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
– Rafael Passos
The estate
Value
begins with a capital v, replaced.value
ford.Value
. Do the same withId
.– Andre
Putz... that’s all it was!!!!!!
– Rafael Passos
puts as an answer, I accept as correct!
– Rafael Passos
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.
– Andre