데이터베이스의 데이터를 바인딩하려고합니다. 무슨 일이 일어나고 있는지는 매 5 초마다 구속된다는 것입니다. 이제 바인딩이 제대로되었지만 이전 데이터는 지워지지 않습니다. 계속 잘 지냅니다. 그래서 3 개의 행이 있다면 .. 단지 3 개의 행만을 보여줄 필요가 있습니다. 현재 일어나고있는 일은 매 5 초마다 3 개의 행을 추가하고 매 5 초마다 6-9-12 행을 유지하는 것입니다. 데이터를 지우고 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()' –
게시물 Akuria를 편집 할 수 있습니다. 텍스트를 백틱으로 감싸거나 4 칸으로 들여 쓰기 코드로 형식을 지정하십시오. – Marco