I'm developing a web application that I use ajax to do from time to time to see if there was a new update, but my code does not work perfectly. I'm new to jquery and I'm having trouble implementing this functionality. I took an example on the net but my does not update the page.
The div I want to update:
<div id="palhetas" class="card-body no-padding">
#{list items:palhetas, as:'p'}
<div class="item d-flex align-items-center">
<input type="hidden" name="palheta.id" value="${p?.id}" />
<div class="text">
<a href="#"> <a href="javascript:void(0)" class="torre">
<input type="hidden" name="palheta.id" value="${p.id}" /> <font
size="3">Agente: ${p.agente.nome}</font>
</a><font size="2"> Endereço: ${p.endereco.rua} </font><br>
<font size="2"> Situação: ${p.situacao} </font>
</div>
</div>
#{/list}
</div>
Ajax script
$(document).ready(function() {
function getData() {
$.ajax({
url: "/Services/listarPalhetas",
beforeSend: function() {$("#palhetas").empty();$("#palhetas").append(<a href="palhetas/detalhesPalhetas?id='+i+'"><div class="item d-flex align-items-center"><div class="text"><font size="3"><center>Agente: '+data[i].agente.nome+'</center></font><font size="2">Endereço: '+data[i].endereco.rua+'</font></div></div></a>');}
}).done(function(data) {
$("#palhetas").empty();
$("#palhetas").append(data);
});
}
getData();
setInterval(getData, 5000);
});