0
Good evening friends, I have the following json which is originated from a url, the result is exactly this:
{
"cod": "OS78946",
"serv": "Pré pago",
"passo": "7894",
"ocorridos": [
{
"data": "21\/02\/2020",
"hora": "19:38",
"onde": "Pato Branco\/PR",
"oque": [
"teste um"
]
},
{
"data": "21\/02\/2020",
"hora": "18:09",
"onde": "Maringa\/PR",
"oque": [
"teste dois"
]
},
{
"data": "21\/02\/2020",
"hora": "17:00",
"onde": "Muriaé\/MG",
"oque": [
"teste oito"
]
}
]}
Follow my code, following this line of reasoning, how to list the values of "date", "time" and "what" that are inside the object "occurred"? I locked in the last line of javascript.
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE-edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
</head>
<body>
<div class="d-flex justify-content-center" id="teste">
<div class="">Resultado
<h5 id="h5-teste"></h5>
<p id="cod"></p>
<p id="serv"></p>
<p id="passo"></p>
<p id="lista_ocorridos"></p>
</div>
</div>
<script type="text/javascript">
$(function(){
$.ajax({
url: 'https://localhost/1.json',
dataType: 'json',
success: function(volta){
if(volta.status == "ERROR"){
alert(volta.message + "Inacessível no momento, tente mais tarde");
return false;
}
$("#cod").html(volta.cod);
$("#serv").html(volta.serv);
$("#passo").html(volta.passo);
//$("#lista_ocorridos")...;
}});
});
</script>
</body>
</html>
occurred is an array, you need to do a for/foreach to list all its values
– Ricardo Pontual