JQuery plugin for realtime update <li> from PHP

is there any jQuery plugin for creating something like a live feed from Twitter Home using PHP that gets data from a MySQL database?
How should a PHP file be?
Thanks.

+2


a source to share


4 answers


You don't really need a plugin to do this, you can easily create something like yourself using jQuery to make AJAX calls to a PHP server PHP

Create a script to make repeated AJAX calls using setTimeout () and then add the new found results to the feed container using . prepend ()

Html



<html>
<head><title>Tweets</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<style>
#tweets {
    width: 500px;
    font-family: Helvetica, Arial, sans-serif;
}
#tweets li {
    background-color: #E5EECC;
    margin: 2px;
    list-style-type: none;
}
.author {
    font-weight: bold
}
.date {
    font-size: 10px;
}
</style>

<script>
jQuery(document).ready(function() {
    setInterval("showNewTweets()", 1000);
});

function showNewTweets() {
    $.getJSON("feed.php", null, function(data) {
        if (data != null) {
            $("#tweets").prepend($("<li><span class=\"author\">" + data.author + "</span> " +  data.tweet + "<br /><span class=\"date\">" + data.date + "</span></li>").fadeIn("slow"));
        }
    });
}
</script>

</head>
<body>

<ul id="tweets"></ul>

</body>
</html>

      

PHP

<?php
echo json_encode(array( "author" => "someone",
                        "tweet" => "The time is: " . time(), 
                        "date" => date('l jS \of F Y h:i:s A')));
?>

      

+7


a source


setInterval () will be more adequate since you want to check at regular intervals.



Then there is the jquery comet plugin, which examines the implementation of the "push" technology. Check here .

0


a source


var frequency = 5000,  // number of milliseconds between updates.

    updater   = function() {
        jQuery.ajax({
            url: 'http://twitter.com/example/something.html',
            success: function(data) {
                // update your page based upon the value of data, e.g.:
                jQuery('ul#feed').append('<li>' + data + '</li>');
            }
        });
    },

    interval  = setInterval(updater, frequency);

      

0


a source


<script>
        $(document).ready(function(){

            var frequency = 10000; // 10 seconds = 10000

            var updater   = function() {
                $.ajax({
                    url: 'mesaj.html', // data source html php
                    cache: false,
                    success: function(data) {
                        $("#message").html(data); // div id
                    }
                }); 
            };

            interval  = setInterval(updater, frequency);
        });
</script>

      

Example

<div id="message">{ do not write }</div>

      

0


a source







All Articles