I want to reload my div names shoutbox:
echo '<div id="shoutbox"><ul>';
$results = $db->query($sql);
foreach ($db->query($sql) as $row) {
echo '<li>';
echo '<span class="date">'.date("d/m/Y H:i", strtotime($row['date_time'])).' </span>';
echo '<span class="name">'.$row['name'].' - </span>';
echo '<span class="message">'.$row['message'].'</span>';
echo '</li>';
}
echo '</div></ul>';
But i don't know how to do that with AJAX... sow the div has to reload when you klik the submit button and every 60 mili-seconds.
if someone can help me, it will be fine.
Michel is on the right track. You should get the data from php, and return json formatted data so that the client can update in javascript. Check out the jquery getJSON function: http://api.jquery.com/jquery.getjson/. Then you set that in a javascript "setInterval" function, like this:
setInterval(function(){
$.getJSON( "ajax/test.json", function( data ) {
var items = [];
$.each( data, function( key, val ) {
items.push( "<li id='" + key + "'>" + val + "</li>" );
});
$( "#shoutbox ul", {
html: items.join( "" )
}).appendTo( "body" );
});
}, 100);
This would reload the array of data every 100 miliseconds.