开发者

Using jQuery Growl with PHP and MySQL

开发者 https://www.devze.com 2022-12-31 06:27 出处:网络
On my database I am planning to create a table storing messages to alert users of anything they need to do.

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>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消