实时评论部分

时间:2013-04-13 03:37:26

标签: javascript jquery ajax comments live-streaming

您好我使用了这个PHP代码:

<?php
if (isset ($_GET['update']))
{
    echo $status;
    die ();
}
?>

和这个javascript:

<script type="text/javascript">
            $(document).ready (function () 
            {
                var updater = setTimeout (function () 
                {
                    $('div#center2').load ('index.php', 'update=true');
                }, 5000);
            });
            </script>

这会刷新我评论的部分,但它基本上会删除评论,并且不会发布任何评论,显示空白。请帮帮我。

1 个答案:

答案 0 :(得分:0)

制作一个action.php文件。

if (isset($_POST['action']) && $_POST['action'] == 'update_comments') {
     // echo all updated comments you want
}

然后在,index.php页面使用像这样的jquery,

var updater = setTimeout (function () {
     $.post("action.php", {action:'update_comments'}, function(data) {
          $('div#center2').html(data);
     }
}, 5000);

此处,在jquery第二行中,action.phpaction.php文件的网址。这个文件可以用于许多其他类似的功能,只需添加更多if循环和动作名称即可。