This is not displayed now.

<table class="table table-hover table-bordered" id="table-get-kre"> <tr class="info"> <th>Опис</th> <th style="text-align: center;">ГРН</th> <th style="text-align: center;">PLN</th> <th style="text-align: center;">EUR</th> <th style="text-align: center;">USD</th> <th style="text-align: center;">Завешення кредитів</th> </tr> <!-- вивести тут --> <!-- вивести тут --> </table> 

Here is the table structure.

Axis table structure

If I comment out echo json_encode($output); in the php file, the style of the top table works fine, here's the screen: https://drive.google.com/open?id=0B0N_1p6wnchMX0h4cHRGNW9pYTg

  • The server response returns all the records in your server; as a result, you have the old rows from the table left and new ones are added after them. Either replace the insert method ( append -> html ), or in response, send only an array with a new record, not all. - MedvedevDev
  • if I change append -> html, then vivoditsa is just one record ((and how can I add only new records? - Alex Kizyma
  • Now I will write in response - MedvedevDev
  • as an option, you can store it in some array of id records that are output, and skip them for further renderings - ddeadlink
  • As for "how to send only new ones" - you somehow create a new record - the same data is only in array format and give back if the creation of a new record in the database was successful. - MedvedevDev

1 answer 1

First create the html variable, then store our lines into it, after the loop we insert it into the table.

 function getTableKredit() { var id; $.ajax({ url:"credit-table.php", cache: false, dataType: "json", success: function(data) { let html = ''; const $table = $('table'), $head = $table.find('tr.info').clone(); for(let item of data) { html += '' + '<tr>' + '<td style="text-align: left;">' + item.description + '</td>' + '<td>' + item.grn + '</td>' + '<td>' + item.pln + '</td>' + '<td>' + item.eur + '</td>' + '<td>' + item.usd + '</td>' + '<td><a href="?kredit=1&id=' + item.id + '" class="delete-kredit">Видалити кредит</a></td>' + '</tr>'; } $table.html(html).prepend($head); } }); } 

PS Although it is better, of course, to give back data only about the new record and insert them through the append .

  • pasted, but now nothing vivoditsa ( - Alex Kizyma
  • @Alex Kizyma, sorry, corrected - MedvedevDev
  • vserovno not vivoditsa nothing ((( - Alex Kizyma
  • @Alex Kizyma, + forgot = / corrected - MedvedevDev
  • Vivelos but now not vivoditsa upper part of the table that is written html - Alex Kizyma