如何只更新由 PHP/MySQL 生成的一列表,而无需重新加载页面/表


how to update just one column of table generatedy by php/mysql with out reloading page/table?

所以我用php从mysql表中获取数据生成了以下HTML表。我想做的是使用 ajax 不断更新最后一行,这样表就不会重新加载整个表。

<tbody>
                    <?php while($row = MySQL_fetch_array($result)):
                    $id = htmlentities($row['id']);
                    $status = htmlentities($row['status']);
                    include ("button.php");
                    ?>
                    <tr>
                        <td title="lname" width="100px">
                            <div style="width:100px; overflow:hidden;">
                                <?php echo(htmlentities($row['last_name'])); ?>
                            </div>
                        </td>
                        <td width="100px">
                            <div style="width:100px; overflow:hidden;">
                                <?php echo(htmlentities($row['first_name'])); ?>
                            </div>
                        </td>    
                        <td width="100px">
                            <div style="width:100px; overflow:hidden;">
                                <?php echo(htmlentities($row['u_name'])); ?>
                            </div>
                        </td>  
                        <td width="100px">
                            <div style="width:150px; overflow:hidden;">
                                <?php echo(htmlentities($row['skype_id'])); ?>
                            </div>
                        </td>
                        <td width="100px">
                            <div style="width:100px; overflow:hidden;">
                                <?php echo(htmlentities($row['primary_location'])); ?>
                            </div>
                        </td>
                        <td>
                            <div style="width:100px; overflow:hidden;">
                                <?php echo(htmlentities($row['phone'])); ?>
                            </div>
                        </td>
                        <td>
                            <div style="width:100px; overflow:hidden;">                                     
                                <?php echo '<div><div id="r'.$id.'"><div id="test"><img class="rating" id="'.$status.$id.'" src="'.$color.'"><div style="display:none;">'.$status.'</div></div></div></div>';?>
                            </div>
                        </td>
                    </tr>                       
                    <?php endwhile; ?>
                </tbody>

我尝试执行以下操作:

<script>
$(document).ready(function(){
  refreshTable();
});
function refreshTable(){
    $('#test').load('response.php', function(){
       setTimeout(refreshTable, 5000);
    });
}
</script>

响应.php只是再次循环了整个 while 循环。问题如下:

1)几秒钟后,页面会越来越慢...反应越来越差。很快它就会停滞不前。我不知道为什么。

2) 刷新可见。每次刷新时,所有表格突出显示都会闪烁片刻。

所以我想,也许如果我只是尝试刷新一列......它不会停滞不前吗?但是,无论我尝试更新列还是会破坏一切,我所有的脚本都会停止工作。而且我不确定如何摆脱表格突出显示在刷新时消失的问题。我怎样才能让这一切发挥作用?

谢谢!

向仅返回 json(或 html,当然由 <tr> 标记包围)格式的最后一行的 URL 发出 ajax 请求。然后,使用 javascript 替换最后一行。