-1
I cannot print the values contained in a string in Jason format using Javascript in a modal containing multiple definition lists. I imagine it’s some syntax error in the access but I couldn’t solve it.
My scenario here is this:.
Here after the query to the database, I do the conversion through PHP of the variable $found for a string in Jason format as follows:
$veiculo_string_jason = json_encode($found);
echo $veiculo_string_jason;
The content of the variable $veiculo_string_jason is as follows:
{"tipo":"Carro","marca":"Citroen","modelo":"Air Cross Salomon Exclusive 1.6 Flex","alimentacao":"Flex","placa":"ABC1234","cor":"Branco","anofab":"2014","anomod":"2015","chassi":"11111111111111111","renavam":"22222222222","valor_compra":"42000.00","valor_venda":"45500.00","situacao":"Consignado","status":"Ativo"}
The Javascript code that makes the whole interface is this one:
// INTERFACE MODAL viewVeiculo
$(document).ready(function () {
$(document).on('click', '.view_data', function () {
var placa = null;
placa = $(this).attr("placa");
if (placa !== '') {
var dados = {
placa: placa
};
$.post('dsVeiculo.php', dados, function (retorna) {
var veiculo = retorna;
$("#var0").html(veiculo.tipo);
$("#var1").html(veiculo.marca);
$("#var2").html(veiculo.modelo);
$("#var3").html(veiculo.alimentacao);
$("#var4").html(veiculo.placa);
$("#var5").html(veiculo.cor);
$("#var6").html(veiculo.anofab);
$("#var7").html(veiculo.anomod);
$("#var8").html(veiculo.chassi);
$("#var9").html(veiculo.renavam);
$("#var10").html(veiculo.valor_compra);
$("#var11").html(veiculo.valor_venda);
$("#var12").html(veiculo.situacao);
$("#var13").html(veiculo.status);
$('#viewVeiculo').modal('show');
});
}
});
});
Id’s from #var0 to #var13 are definition lists.
<dl class="row mb-0">
<dt class="col-sm-6 text-right">Tipo:</dt>
<dd id="var0" class="col-sm-6"></dd>
</dl>
I sought help on these topics but without success.
You need to parse in Sponse.
var veiculo = jQuery.parseJSON( retorna );
– Igor Mello
@Igormello made the correction and it worked, now I can access each element of the string.
– Flávio Kowalske