1
I am developing a web application that I use ajax to request from time to time to find out if there has been a new update, but my code does not work perfectly. I’m new to jquery and I’m having trouble implementing this feature. I got an example on the net but mine does not update the page.
The div I intend 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);
});
giving the error: Uncaught Syntaxerror: Unexpected Dentifier on the line: $("#straws"). append('<a href="straws/detailsPallists? id='+i+'"><div class="item d-flex align-items-center"><div class="text"><font size="3"><center>Agent: '+data[i].agente.name+'</center></font><font size="2">Address: '+data[i].endereco.street+'</font></div></div></div></a>');
– Carlos Diego
What would that be
i
indata[i]
?– Sam
my input of an array of palettes
– Carlos Diego
Added in the answer. Just make a loop.
– Sam