Reload table Ajax jquery -


i developing table , table reload ajax/jquery table doesn't empty , append next content table.

<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> 

any idea ? how refresh table correctly?

try:

add tbody id

 <tbody id='tbodyid'> 

and clear before append

$("#tbodyid").empty(); 

in code

  function json(data){                    $("#tbodyid").empty();                    $(data).each(function(index,value)  {                    ... 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -