0

我有一个循环帖子并允许用户对每个帖子发表评论的时间线。输入评论后,它意味着添加到发表评论的帖子之前。现在的问题是它在第一个帖子之前。这意味着此前置操作未遵循循环。

添加评论功能

<!--Function to add comment-->
var msg2 = $("#feeds li #comment-form #comment");
var msg = $("#feeds #comment-form #hidden");
var textarea = $('#comment');
$('.comment-btn').on("click",function(event) {
    var one = $(this).parent().find(msg2).val();
    var two = $(this).parent().find(msg).val();

     $.ajax({
        type: "POST",
        url: "add_comment.php",
        data: "msg2="+ one +"&msg=" + two,
        msg: "Checking...",
            success: function(data){
    $('#feeds li #comment-form').parent().find('textarea').val("");
    updateComment();
            }
        });
});

这是 updateComment 函数

<!--Function to update the comment feed-->
function updateComment(){
    var id = 0;
    id = $('#feeds li #other-comments').attr('data-id');
    $.ajax({
        'url' : 'comment.php',
        'type' : 'POST',
        'data' : {
            'latest_comment_time' : id
        },
        success : function(data){
            if(id != 0){
                $('#sub-comments').prepend(data);
            }
        }
    }) 
}  

已编辑

html

                    <div id='comments'>
                <form action='' id="comment-form" method="post">
                <textarea id="comment" name="comment" placeholder="Add comment..."></textarea>
                <input type="button" class='comment-btn' value='Send'>
                <input type="hidden" name="msg" value="<?=$item['msg_id']?>" id="hidden">
                </form>
                <div id="sub-comments">
                <?php require('comment.php');?>
                </div>
                </div>

注意:'feeds li' 用于循环帖子。

4

0 回答 0