Using .append () or .html () - jQuery

0

I'm not able to insert html into an element.

JS

function carregaAgendamento() {
var url = "http://prestoexpress.com.br/vistoria/json.php";
$.getJSON(url, function(result) {
  console.log(result);
  $.each(result, function(i, field) {

    var id = field.id;
    var dataVistoriaAgenda = field.dataVistoriaAgenda;
    var tipoImovel = field.tipoImovel;
    var tipoVistoria = field.tipoVistoria;
    var codImovel = field.codImovel;

    $("#vistoria-agenda").append('<li><a href="#"><h2>'
      +codImovel+" "+dataVistoriaAgenda+'</h2><p>'
      +"Tipo: "+tipoVistoria+" Tipo Imóvel: "+tipoImovel+'</p></a></li>');
   });
 });
};

HTML

<body>
<p>Vistorias Agendadas</p>
<ul id="vistoria-agenda" data-role="listview" data-inset="true">

</ul>
</body>
    
asked by anonymous 01.02.2017 / 22:46

1 answer

1

Ezekiel, the site was unavailable at the time of my response, so I created a json.php file to serve as a test and pasted your json that you wrote in the comment on it. I removed the questions (??) from json's medium so as not to give error. I called in your function and it worked fine.

Output example:

  

Scheduled Surveys

     

16524 2017-02-06

     

Type: Exit Property Type: Residential

Here is the code used to test:

json.php

[{"id":"1","dataVistoriaAgenda":"2017-02-06","dataVistoria":"0000-00-00 00:00:00","endereco":"Rua São Rafael, 34","tipoImovel":"Residencial","comentarios":"","tipoVistoria":"Saída","status":"Pendente","codImovel":"16524"}]

index.php

<!DOCTYPE html>
<html>
<head>
<title>Teste Carrega Agendamento</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script><script>functioncarregaAgendamento(){//varurl="http://prestoexpress.com.br/vistoria/json.php";  // Site indisponível no momento

    var url='json.php'; // com json fake informado no comentário pra ver rodando
                        // Apenas removi umas "??" para não dar erro 

    $.getJSON(url, function(result) 
    {

      console.log(result);
      $.each(result, function(i, field) 
      {
            var id = field.id;
            var dataVistoriaAgenda = field.dataVistoriaAgenda;
            var tipoImovel = field.tipoImovel;
            var tipoVistoria = field.tipoVistoria;
            var codImovel = field.codImovel;

            $("#vistoria-agenda").append('<li><a href="#"><h2>' + codImovel + ' ' + dataVistoriaAgenda + '</h2><p>' +
            ' Tipo: ' + tipoVistoria + '<br>'+
            ' Tipo Imóvel: ' + tipoImovel + '</p></a></li>');
       });

    });

};  

window.onload=carregaAgendamento;
</script>   

</head>
<body>

    <p>Vistorias Agendadas</p>
    <ul id="vistoria-agenda" data-role="listview" data-inset="true">

    </ul>

</body>
</html>
    
02.02.2017 / 12:50