Ajax feed auto-refresh

I got an auto-refresh snippet of code called News feed master and I have managed to implement and customize it to my own taste. Everything seems to be working except the auto-refresh which is meant to show my new post as I input it instead of having to refresh the whole page. Here is a section of my index.php that queries the database for new feeds query("SELECT * FROM users U, messages M WHERE U.user_id = M.uid_fk AND M.created > '".$_POST['latest_news_time']."' ORDER BY M.created DESC"); $current_time = $_POST['latest_news_time']; $item = $db->fetch_assoc($result); $last_news_time = $item['created']; while ($last_news_time < $current_time) { usleep(1000); //giving some rest to CPU $item = $db->fetch_assoc($result); $last_news_time = $item['created']; } ?>
  • <?=$item['image']?>



  • And here's a section of my javascript that is supposed to perform the auto-refresh /** * Function to update the news feed **/ function updateFeed(){ var id = 0; id = $('#feeds li :first').attr('id'); $.ajax({ 'url' : 'index.php#feeds ul', 'type' : 'POST', 'data' : { 'latest_news_time' : id }, success : function(data){ setTimeout('updateFeed()', 1000); if(id != 0){ $(data).prependTo("#feeds ul"); } } }) } I would be glad if you could help spot out the problem. I'm not a pro in jquery at all so it's giving me sleepless nights. Thanks.

    以上就是Ajax feed auto-refresh的详细内容,更多请关注web前端其它相关文章!

    赞(0) 打赏
    未经允许不得转载:web前端首页 » jQuery 答疑

    评论 抢沙发

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址

    前端开发相关广告投放 更专业 更精准