简体   繁体   English

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

[英]Real-time jquery popup based on php return values

Im having a php program that will calculate the time difference and return the value in minutes. 我有一个PHP程序,将计算时间差并以分钟为单位返回值。

for the message popup i use jGrowl 对于消息弹出窗口,我使用jGrowl

so what i would like to do is get the return value and if its less than 30 minutes display the jquery message. 所以我想做的就是获取返回值,如果返回值少于30分钟,则会显示jquery消息。

and most importantly it should be running live. 最重要的是它应该可以实时运行 so if a user is in a page without navigating or refreshing, if the time is less than 30 minutes the popup should appear real-time. 因此,如果用户在没有导航或刷新的页面中,如果时间少于30分钟,则弹出窗口应实时显示。

can someone please suggest me how to use the return value to achieve the above requirement? 有人可以建议我如何使用返回值来达到上述要求吗?

Below if the code that im using to calcutale the time differnce 下面是我用来计算时差的代码

    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;
    }

currently im poping up only the messages on date 目前我只弹出日期的消息

<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>

Have a php script that takes passed parameters, in this case the two times. 有一个采用传递参数的php脚本,在这种情况下是两次。 Write the script to return the results as JSON. 编写脚本以将结果返回为JSON。 This is the part I assume you already have done. 这是我认为您已经完成的部分。 If you don't have the results returning as as JSON string you can read up on JSON here . 如果您没有将结果作为JSON字符串返回,则可以在此处阅读JSON

In your webpage, make the request with javascript & ajax. 在您的网页中,使用javascript和ajax发出请求。 Basically, when the user clicks a button, send the info asynchronously to your php script, and when the response is received display the inf to the user. 基本上,当用户单击按钮时,将信息异步发送到您的php脚本,并在收到响应时将inf显示给用户。 You can read up on Javascript & Ajax here . 您可以在此处阅读Javascript和Ajax

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

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