自动刷新包含DIV内的PHP文件 [英] Auto refresh included PHP file inside a DIV

查看:74
本文介绍了自动刷新包含DIV内的PHP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为messages.php的文件,它运行SQL查询到数据库并在 $ res 变量中显示结果

I have a file called messages.php which runs SQL queries to a database and displays results in a $res variable

我使用的menu.php页面

My menu.php page I used

include 'messages.php';

然后:

<div id="msgs">
<?php echo $res; ?>
</div>

这样就显示了 $ res 来自menu.php div中的messages.php页面的变量

So this displays all the data in the $res variable from the messages.php page in a div on menu.php

如何让它自动刷新,以便中的任何新数据$ res 变量显示而无需刷新menu.php页面?

How can i make this automatically refresh so any new data in the $res variable displays without having to refresh the menu.php page?

推荐答案

首先删除包含' messages.php;
然后删除echo $ res;从div并把它放在messages.php的最后一行

First Remove include 'messages.php'; Then remove echo $res; from div and put it in the last line of messages.php

并在包含jquery文件之后尝试以下代码

and try the following code after including the jquery file

<script>
jQuery().ready(function(){
    setInterval("getResult()",1000);
});
function getResult(){   
    jQuery.post("messages.php",function( data ) {
        jQuery("#msgs").html(data);
    });
}
</script>
<div id="msgs">
</div>

这篇关于自动刷新包含DIV内的PHP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆