刷新表使用jQuery /阿贾克斯每5秒 [英] Refresh a table with jQuery/Ajax every 5 seconds
本文介绍了刷新表使用jQuery /阿贾克斯每5秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,我有一个表从数据库中提取信息,我想知道我怎么可能让它刷新其信息,而无需重新加载整个页面。
So I have a table pulling information from a database and I was wondering how I could make it refresh its information without reloading the whole page.
推荐答案
您将需要一个 getTable.php
页面,该页面会显示您的表,而不是其他:无标题,页脚等。
You'll need a getTable.php
page that displays your table, and nothing else: no headers, footers, etc.
PHP(getTable.php) - 这可以是任何服务器端code(ASP,HTML等)
<?php
echo '<table><tr><td>TEST</td></tr></table>';
?>
然后,在你的JS,你可以很容易地通过 load()的刷新表
方法:
HTML
<div id="tableHolder"></div>
JS
<script type="text/javascript">
$(document).ready(function(){
refreshTable();
});
function refreshTable(){
$('#tableHolder').load('getTable.php', function(){
setTimeout(refreshTable, 5000);
});
}
</script>
这篇关于刷新表使用jQuery /阿贾克斯每5秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文