基于php返回值的实时jquery弹出窗口

时间:2012-07-24 17:03:18

标签: php jquery ajax jgrowl

我有一个PHP程序,它将计算时差并以分钟为单位返回值。

对于我使用jGrowl

的消息弹出窗口

所以我想做的是获取返回值,如果小于30分钟,则显示jquery消息。

最重要的是它应该是现场直播。因此,如果用户在页面中没有导航或刷新,如果时间少于30分钟,则弹出窗口应该是实时显示的。

有人可以建议我如何使用返回值来达到上述要求吗?

下面,如果我用来加速时间差异的代码

    function time($dbtime, $currtime)
    {
        //format year-month-day hour:min:secs
        $current = strtotime($currtime);
        $indb = strtotime($dbtime);
        $minits =  round(abs($current - $indb) / 60,2);

        return $minits;
    }

目前我只弹出日期消息

<script type="text/javascript">

        (function($){

            $(document).ready(function(){

                // jGrowl
                if ($.fn.jGrowl) {
                    // This value can be true, false or a function to be used as a callback when the closer is clciked
                            $.jGrowl.defaults.closer = function() {
                                console.log("Closing everything!", this);
                            };

                            // A callback for logging notifications.
                            $.jGrowl.defaults.log = function(e,m,o) {
                                $('#logs').append("<div><strong>#" + $(e).attr('id') + "</strong> <em>" + (new Date()).getTime() + "</em>: " + m + " (" + o.theme + ")</div>")
                            }               


                            <?php foreach ($dailies as $daily):?>
                            $.jGrowl("<?php echo $daily['calendars'][0]['Title']?>", { header: 'At <?php echo $daily['calendars'][0]['Start'];?>', sticky: true });


                            <?php endforeach;?>

                            $.jGrowl.defaults.closerTemplate = '<div>hide everything</div>';


                }

            });
        })(jQuery);

    </script>

1 个答案:

答案 0 :(得分:0)

有一个PHP脚本,它接受传递的参数,在这种情况下是两次。编写脚本以将结果作为JSON返回。这是我假设你已经完成的部分。如果您没有像JSON字符串那样返回结果,则可以read up on JSON here

在您的网页中,使用javascript&amp;阿贾克斯。基本上,当用户单击按钮时,将信息异步发送到您的php脚本,并在收到响应时向用户显示inf。你可以read up on Javascript & Ajax here