I am trying to make a newsfeed for a webpage. Though the only problem I have encountered is refreshing the posts. How can I refresh the newsfeed only when new data has been inserted to mysql database? As you can see, pagerefresh() is being called every 5 seconds but thats inefficient because I am printing the data over and over again. Also when a user is trying to comment on the newsfeed, the posts keeps getting refreshed thus interrupting the user from his typing. I haven't included all the code, but my main question is how can you refresh only when new data has been entered?
header.php
function initializePosts()
{
$.post("searchPresentation.php", {refresh_posts:"yes", user: "<?php echo $user ?>"}, function ( data ){
$("#profile_newsfeed2").html(data);
});
setTimeout("initializePosts();", 5000);
}
index.php
<script>
initializePosts();
</script>
<div id="profile_newsfeed2"> </div>