I'm trying to fill a dropdown menu which, when the torina is put on a button this works.
But since I want this padding to happen automatically as soon as the document is loaded, I jQuery.ready () for this, however, the function it invokes does not work, ie the menu is not being populated.
Current code:
function PreencheCombo() {
var str = "";
$.ajax({
url: '/Cadastro/PreencheComboUf',
datatype: 'json',
contentType: "application/json; charset=utf-8",
type: "POST",
success: function (data) {
str += '<label for="cbxUf" class="col-sm-4 control-label">UF</label>';
str += '<select class="form-control col-sm-4" name="cbxUf" id="cbxUf">';
$(data.result_combo).each(function () {
str += '<option value=' + this.sigla + '>' + this.descricao + '</option>';
})
str += '</select>';
$('#combo').html(str);
},
error: function (error) {
}
})
}
And the invocation:
$(document).ready(function () {
PreencheCombo();
});
If I put a button to call the FillCombo function there, then it's ready that is not working.