0
Hi, how are you? I am trying to make popular a select with Json that already comes selected item. I managed to make until the select population listing all the models of cars just could not already bring it selected. Can anyone help me?
var handlerCarregaMarca = function(){
var marca = $('#tipo-id').val();
var marcaid = $('#marca-id').val();
console.log(marca);
console.log(marcaid);
$.ajax({
type: "GET",
url:'listarMarcas?codigo='+marca,
dataType: "html",
async:false,
success: function (data) {
// console.log(data);
var output= '<option value="">Selecione o Tipo do Veiculo</option>';
var dados = JSON.parse(data);
$.each(dados, function(i, item){
output += '<option value="'+item.marc_id+'""'+item.marc_id == marcaid ? 'selected':''+'">'+item.marc_nome+'</option>'
});
$("#marca-veiculo").html(output);
$("#marca-veiculo").trigger('chosen:updated');
}
});
$(this).val(marca);
That’s the code I’m using.
can put an example of json return
data
– Costamilam
The date returns thus marc_display : "1" marc_photo : "Fiat.jpg" marc_id : "1" marc_name : "Fiat" marc_type : "1"
– TI Lider
I can list everything neat, what I can’t get I’ve already selected know, I can do this in html but in json will not.
– TI Lider
dataType
, naydata
, as William Costamilam said, is waiting for a resultHTML
. Switch toJSON
.– William Aparecido Brandino