データベースからデータをバインドしようとしています。起こっていることは、5秒ごとにバインドすることです。今はバインドが正しく行われていますが、以前のデータはクリアされません。それはうんざりし続ける。したがって、3つの行がある場合は、3つの行だけを表示する必要があります。今起こっていることは、5秒ごとに3行を追加し、5秒ごとに6-9-12をpillingし続けることです。 データをクリアしてから5秒ごとにロードする必要があります。テーブル内のデータを再配置する前にテーブルをクリアする
<script type="text/javascript">
$(document).ready(function() {
Get();
setInterval(function() {
Get() // this will run after every 5 seconds
}, 5000);
});
function Get() {
$.ajax({
type: "POST",
url: "../adminpage/noti.ashx",
data: {},
dataType: "json",
success: function (response) {
$.each(response, function (index, itemData) {
var tr = "<tr>" +
"<td>" + itemData.msg + "</td>" +
"<td>" + itemData.dt + "</td>" +
"</tr>";
$("#testTable").find("tbody").append(tr);
});
BindTable();
}
});
}
function BindTable() {
try {
$('#testTable thead th').each(function (i) {
var title = $('#testTable thead th').eq($(this).index()).text();
if (title != "") {
$(this).html('<div style="width:40%;text-align:center;white-space:nowrap">' + title + '</div>');
}
});
}
catch (e) { }
}
</script>
<table id="testTable" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th class="m-list-timeline__text" style="width:70%">msg</th>
<th class="m-list-timeline__time" style="width:30%">dt</th>
</tr>
</thead>
<tbody></tbody>
</table>
'$('#testTable ')。empty()' –
あなたの投稿を編集することができます。あなたのテキストをコードで書式設定してバッククォートで囲むか、4つのスペースでインデントしてください – Marco