My table is appended to instead of updated. What would be the appropriate way to update the html. I tried to use the answer from a similar stackoverflow question but it didn't work.
Here's my webpage, which uses Bootstrap, and the relevant ajax:
<div class="bs-component">
<table class="table table-striped table-hover ">
<thead>
<tr>
<th style="font-size: 25px">Week <span id="week" style="font-size: 28px">1</span></th>
<th>12 am - 8 am</th>
<th>8 am - 12 pm</th>
<th>12 pm - 4 pm</th>
<th>4 pm - 8 pm</th>
<th>8 pm - 12 am</th>
</tr>
</thead>
<tbody>
<script>
function loadWeek (x) {
$.post("weekly.php", {p: x}, function (res) {
//$("tbody").append(res);
$('#bs-component table > tbody:last').find('tr:first').before(res);
});
}
$(function () {
loadWeek (1);
});
</script>
</tbody>
</table>
Here's the html echoed by the php called by ajax
for ($i = 0; $i < 7; $i++) {
echo "<tr><td>$weekDays[$i]</td>";
for ($j = 0; $j < 5; $j++) {
echo "<td><p>".$usersNames[$i][$j]."</p></td>";
}
echo"</tr>";
}
replaceWith()orreplaceAll()?