我有一个页面显示插入到 mysql 数据库中的数据;我希望(如果可能的话)当将记录添加到数据库时,此 View 页面会自动更新(数据不是从同一页面插入的,或者可能是从其他用户插入的)。
提前致谢 再见。
最佳答案
第一种方法(最简单但烦人):
向页面添加元刷新,整个页面每 x 时间刷新一次。
第二种方式(AJAX):
我假设这就是你想要的。
- 加载默认 HTML 页面等...我们将其命名为index.php
在上面的页面上创建一个
元素,其样式为 display:none<div id="mydata" style="display: none;"></div>
创建一个 PHP 页面,用于检索和格式化数据库数据,并以 x 格式(即表或 p 标签)打印出来。没有标题或页面特定的内容,只有数据和简单的标签
在index.php上放这样的东西
<script type="text/javascript"> function update() { $.ajax({ url: 'http://www.example.com/getData.php?q=latest', success: function(response) { $('#mydata'.html(response); } }); } // .ready function $(function() { // do setup stuff here, I think there is a refresh timer or something // that you'd use to trigger it every x amount of time // i.e something like this update(); }); </script>
编辑:AJAX HTTP streaming强制将数据输出给用户
关于php - 数据库更新时jquery更新页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3415344/