duandianwen1723 2010-05-25 00:34
浏览 30
已采纳

使用jQuery Growl与PHP和MySQL

On my database I am planning to create a table storing messages to alert users of anything they need to do.

I am looking at using a jQuery growl like notification method but I'm confused at how I would begin building it.

The data would be added into the database using the standard MySQL insert method from a form but how would I select messages from the database to display using the jQuery growl.

Would this require the use of AJAX?

This is the JavaScript code I have so far, i was wondering how I would implement the PHP code alongside it so that I can pull out data from my tables to display as notifications:

        <script type="text/javascript"> 

    // In case you don't have firebug...
    if (!window.console || !console.firebug) {
        var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
        window.console = {};
        for (var i = 0; i < names.length; ++i) window.console[names[i]] = function() {};
    }

    (function($){

        $(document).ready(function(){

            // This specifies how many messages can be pooled out at any given time.
            // If there are more notifications raised then the pool, the others are
            // placed into queue and rendered after the other have disapeared.
            $.jGrowl.defaults.pool = 5;

            var i = 1;
            var y = 1;

            setInterval( function() {
                if ( i < 3 ) {
                    $.jGrowl("Message " + i, {
                        sticky:         true,
                        log:            function() {
                            console.log("Creating message " + i + "...");
                        },
                        beforeOpen:     function() {
                            console.log("Rendering message " + y + "...");
                            y++;
                        }
                    });
                }

                i++;
            } , 1000 );

        });
    })(jQuery);

    </script>                     
                <p>

</span>
<p>
  • 写回答

1条回答 默认 最新

  • dousou3027 2010-05-25 01:58
    关注

    PHP is running on the server and JavaScript is running on the client.

    So Yeah, you'll need AJAX.

    Well, there would be other ways, but they are more work than simply setting up AJAX. Especially so since you work with jQuery which handles most of the AJAX stuff for you.

    Let it call a small PHP script that fetches the Rows from the DB, outputs them in your preferred Way (XML or JSON) and exits.

    The usual jQuery AJAX tutorials should cover exactly that.

    If your App is Multi-User don't forget to send a UserID in the Request so PHP knows what Rows to pull.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度