0

In my web site timeline, I want to just append new update after a time interval like facebook timeline. So I read about many article about comet, long poll, web socket etc here and many where in web. But I can understand how to implement any script to append new update only without refresh page or any div.

I have not enough knowledge about jQuery, Javascript. But I already solved many more problem with Stackoverflow's help. So please help me to do it as a newbie.

You can also say me to give some working example that not work. But I cannot understand how and what to do.

Here I give my timeline and wall related all script.

My comment.php

function getComments($userwallid){
$results = mysqli_query($dbh,"SELECT * FROM comments_lite WHERE qazi_id='$userwallid' ORDER BY id DESC LIMIT 20") or die(mysqli_error($dbh));

            echo '<div class="comments"><div id="updates">';

while($rows = mysqli_fetch_assoc($results)) {
    $id = $rows['id'];
    $uesrpage_id = $rows['userpage_id'];
    $likes = $rows['likes'];
    $username = $rows['username'];
    $description = $rows['description'];        
    $date = $rows['date'];
    // etc all..
            echo'<div class="case postcom'.$id.'"><div class="comment">
            <div class="cdomment_cheder">
            <div class="avatarcnt">
            <img alt="" src="uploadprofile/'.$u_imgurl.'"/></div><div class="newkochi">';
            if ($url=="") {
            echo'<p class="name">'.$username.' Says:</p>'; }
            else  echo'<p class="name"><a href="'.$url.'" title="'.$username.'">'.$username.'</a> Says:</p>';
            echo'<span class="cdomment_time">'.$date.'</span>
            <div class="cdomment_text">';
            if ($description=="") {echo '';}
            else echo''.nl2br(smileys($description)).'<br>';
            if ($img=="") {echo '';}
            else echo'<br><img src="comimage/'.$img.'" />';
            echo '</div>';
    //delete button
    //Likes button

            echo'</div></div></div></div>';

    //Reply script goes here...
            echo 'same as aove';
}

Timeline page

<div class="timelineupdate">
<?php 
include_once('comment.php'); 
getComments("$uesrid");
?>
</div>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
koc
  • 955
  • 8
  • 26
  • The requirement is to show what you have attempted *with regard to your question*. Showing the bit that renders static content is not helpful as you still basically want others to show you how to write basic jQuery Ajax calls *which is not the purpose of SO*. – iCollect.it Ltd Feb 20 '15 at 12:22
  • Add PHP tag to your question – Alexander Dayan Feb 20 '15 at 12:22

2 Answers2

0

Do some thing using ajax calls like this

function callMe()
    {
        $.ajax({
               type: "GET",
               url: "MyComment.php",
               data: "id=1",
               success: function(response){
                          $("#testDiv").html(response);
                        }
       });
    }

// Call it
setInterval(callMe, 5000); //every 5 secs
nifCody
  • 2,394
  • 3
  • 34
  • 54
  • I am trying it, but it seem it's load full #testdiv after time interval. – koc Feb 20 '15 at 13:00
  • so you need some update values am i right? If yes its a good way when ever getting some data from the file you store thats id into temperory varaiable and then get back affter which are not in the array – nifCody Feb 20 '15 at 13:04
  • Please see my above timeline page code. To get user date I sent user id by `getComments("$uesrid")`; in comment.php page. And 1st line of comment.php page I used user id as function `getComments($userwallid)`. How to do it with your script, because after 5 sec your `.timelineupdate` show nothing. – koc Feb 20 '15 at 13:49
  • Have you adding the jquery library – nifCody Feb 20 '15 at 14:41
0

It's really not that complicated in JS/PHP :

(JS) :

setInterval(poll,2000);

function poll(){
     $.get( 'poll.php', function(content){
           $('#pollContainer').prepend(content);
     });
}

In NodeJS, with socketIO, you would go :

(Server):

socket.emit( 'new content', content );

(Client):

socket.on( 'new content', function(content){
     $('#pollContainer').prepend(content);
});
Jeremy Thille
  • 26,047
  • 12
  • 43
  • 63
  • Thank u sir. Don't mind please, what is it "In NodeJS, with socketIO, you would go :" – koc Feb 20 '15 at 12:59
  • NodeJS is a javascript web server. It becomes more and more popular. I mentioned it because you talked about web sockets. SocketIO is a webSocket extension for NodeJS. There's plenty of documentation around (see http://stackoverflow.com/questions/1884724/what-is-node-js). If you think my answer is satisfying, please upvote and validate it (green tick) :) – Jeremy Thille Feb 20 '15 at 14:22