重新加载表ajaxjquery
我正在开发一个表,该表使用ajax/jquery重新加载,但表不为空,将下一个内容附加到表中重新加载表ajaxjquery,jquery,ajax,tabs,Jquery,Ajax,Tabs,我正在开发一个表,该表使用ajax/jquery重新加载,但表不为空,将下一个内容附加到表中 <table class="table" id="pujas"> <thead> <tr> <th>#</th> <th>Nombre</th> <th>Apellido</th>
<table class="table" id="pujas">
<thead>
<tr>
<th>#</th>
<th>Nombre</th>
<th>Apellido</th>
<th>Email</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
#
名义
阿佩利多
电子邮件
Jquery
<script>
$(document).ready(
function() {
setInterval(function() {
$.ajax({
url:'../ajaxpujas',
dataType:'json',
type:'get',
cache:true,
success:json,
});
function json(data){
$(data).each(function(index,value) {
console.log(value);
var table = '<tr><td>' + value.id + '</td><td>' + value.id_user + '</td><td>' + value.importe + '</td></tr>';
$('#pujas').append( table );
});
}
}, 1000);
});
</script>
$(文件)。准备好了吗(
函数(){
setInterval(函数(){
$.ajax({
url:“../ajaxpujas”,
数据类型:'json',
类型:'get',
是的,
成功:json,
});
函数json(数据){
$(数据)。每个(函数(索引、值){
console.log(值);
变量表=“”+value.id+“”+value.id\u用户+“”+value.importe+“”;
$('pujas')。追加(表);
});
}
}, 1000);
});
你知道吗?我如何才能正确地刷新表?您使用的是append,而不是append元素。 通过使用“.HTML()”并将HTML添加到当前HTML,可以从var表中添加HTML
另一种方法是实际创建元素,然后使用.append在重新加载新内容之前,您必须先清理
内容
但是,在这种情况下,您应该从
元素中添加和管理表内容,以保留上面的
因此,在json函数中,您可以执行以下操作:
$('#tbody_id').html (""); // This cleans the previous content.
然后在进行操作时添加新内容:
$('#tbody_id').append ('Your html content');
尝试:
添加tbody id
<tbody id='tbodyid'>
在代码中
function json(data){
$("#tbodyid").empty();
$(data).each(function(index,value) {
...
function json(data){
$("#tbodyid").empty();
$(data).each(function(index,value) {
...