简体   繁体   English

检查更新和刷新页面

[英]Check Update and Refresh Page

I Have a Messaging web application whose conversation page needs to check for a new message at a fixed interval (say 10 sec) and refresh itself if any new message available.我有一个消息 Web 应用程序,其对话页面需要以固定时间间隔(例如 10 秒)检查新消息,并在有新消息可用时自行刷新。 I don't want to put a static HTML refresh as it causes page to reload even if no new message is there !我不想进行静态 HTML 刷新,因为即使没有新消息,它也会导致页面重新加载!

Any help is widely appreciated !!任何帮助都受到广泛赞赏!

You could try something like this:你可以尝试这样的事情:

(function($)
{
    $(document).ready(function()
    {
        $.ajaxSetup(
        {
            cache: false,
            beforeSend: function() {
                $('#content').hide();
                $('#loading').show();
            },
            complete: function() {
                $('#loading').hide();
                $('#content').show();
            },
            success: function() {
                $('#loading').hide();
                $('#content').show();
            }
        });
        var $container = $("#content");
        $container.load("page.php");
        var refreshId = setInterval(function()
        {
            $container.load('page.php');
        }, 9000);
    });
})(jQuery);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM