jquery - I am trying to make something like Facebook comment functionality. Read description what I am missing -


my comments posting through ajax fine when click on like, count not update. if refresh page once, , click on like, count updates through ajax. missing?

why ajax call on clicking not occurring when post new comment. please help.

here code.

jquery :

this part of code adds comment through ajax, submission via pressing enter

  $('textarea').keyup(function (event) {                 if (event.keycode == 13 && event.shiftkey) {                     var content = this.value;                     var caret = getcaret(this);                     this.value = content.substring(0,caret)+                                   "\n"+content.substring(caret,content.length);                     event.stoppropagation();                 } else if(event.keycode == 13) {                      $.ajax({                                                 type: "post",                                    url: 'index2.php',                                    data: $("#comment-form").serialize(),                                    success: function(data)                                    {                                         $("#results").html(data);                                    }                                  });                                  $("#comment").val('');                          e.preventdefault();                }               }); 

this part of code explains count updating

              $("span[id^='comlike'] a").click(function() {                 //  alert('aaa');                 var idtest;                 idtest = $(this).attr('id');                 var mystring = idtest;                 var parts = mystring.split("like");                 var thepart = parts[1];                     $.ajax({                                                 type: "post",                                    url: 'like.php',                                    data: 'likeid='+thepart, // serializes form's elements.                                    success: function(data)                                    {                                       $("#likecount"+thepart).html(data);                                      }                                  });                 }); 

html:

this part of code html comments posting through ajax

while($row = mysql_fetch_array($q)) {    echo  '<div id="divcommentid_'.$row['id'].'">'.           $row['comment'] .            '<br>'           . '<div>'              . '<span style="color:#999">posted : '.$row['time'].'</span>&nbsp;'              . '<span id="comlike'.$row['id'].'">'                 . '<a href="#" id="like'.$row['id'].'">like</a>'                 . '&nbsp;'.''                 . '<span style="color:blue" id="likecount'.$row['id'].'">'.$row['like_count'].'</span>'             . '</span>'           . '</div></div>';  }?></div><br>             <form role="form" id="comment-form" method="post" action="">                   <textarea class="form-control resizable comment-box required" rows="1" placeholder="write comment" id="comment" name="comment" size="80" ></textarea>                  <br>               <!--        <input type=text class="form-control comment-box" rows="1" placeholder="write comment" id="comment" name="comment">    -->                  <input type="hidden" name="time" value="<?php echo $date; ?>" />             </form> 

this commentid div on index2.php also, responded update html of div id "results"

my comments posting through ajax fine when click on like, count not update. if refresh page once, , click on like, count updates through ajax. missing?

why ajax call on clicking not occurring when post new comment.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -