Javascript 在回复提交中,只有第一条评论回复有效

Javascript 在回复提交中,只有第一条评论回复有效,javascript,jquery,ajax,Javascript,Jquery,Ajax,我在做一个大项目。我被困在评论回复系统。它在Ajax中运行良好,但当我发布第二条或另一条评论回复时,文本区域显示为空。为什么只成功提交了第一个回复?这是我的密码: $(document).ready(function(){ $(".post_reply").click(function(rp) { rp.preventDefault(); var box_id = $(".bid").val(); var ownerc = $(".owne

我在做一个大项目。我被困在评论回复系统。它在Ajax中运行良好,但当我发布第二条或另一条评论回复时,文本区域显示为空。为什么只成功提交了第一个回复?这是我的密码:

$(document).ready(function(){
    $(".post_reply").click(function(rp) {
        rp.preventDefault();
        var box_id = $(".bid").val();
        var ownerc = $(".owner").val();
        var replyc = $(".reply").val();
        var commentc_id = $(".comment_id").val();
        var dataString = 'bid='+ box_id + '&owner=' + ownerc + '&comment_id=' + commentc_id + '&reply=' + replyc;
        alert(replyc);

        if(ownerc=='' || box_id=='')
        {
            alert('Please Give Valide Details');
        }
        else
        {
            $.ajax({
                type: "POST",
                url: "sub_comment.php",
                data: dataString,
                cache: false,
                success: function(replys){

                    $('#replys'+commentc_id).append(replys);
                    $(".reply").val('');
                }
            });
        }
        return false;
    });
});
这是评论系统的全部代码

       <h3>User Comment</h3>
                <div class="comments_area">
        <?php
        $comments=mysql_query('select * from comments where bid="'.$_GET['id'].'"');
        while($get_info=mysql_fetch_array($comments)){
        $comment=$get_info['comment'];
        $comment_id=$get_info['id'];
        $cuid=$get_info['uid'];
        $c_users=mysql_query('select user_name,thumb from users where id="'.$cuid.'"');
        $get_uinfo=mysql_fetch_array($c_users);
        $cname=$get_uinfo['user_name'];
        $cimage=$get_uinfo['thumb'];
        if(strpos($cimage,'https://') !== false) {
$cthmbs=$cimage;
}else
{
$cthmbs='images/thumbs/'.$cimage;
}

        ?>

      <div class="user-comment">
        <h2 style="float:left;clear:both;display:block;margin:0px auto auto 70px;"><a style="color: rgb(5, 41, 84);text-decoration:none;" href="profile.php?id=<?php echo$cuid;?>"><?php echo $cname;?></a></h2>
        <p style="position:relative;float:left;clear:both;display:block;margin:auto auto auto 70px;"><?php echo $comment;?></p>
        <a style="color: rgb(5, 41, 84);text-decoration:none;" href="profile.php?id=<?php echo$cuid;?>"><img style="margin:-32px auto auto auto;float:left;clear:both;dislay:block;overflow:Hidden;" src="<?php echo$cthmbs;?>" width="60" height="60" alt="" /></a>
        <div class="user-comment-stuff">
            <div class="user-comment-stuff">
                    <ul>
                        <li ><img src="images/likes-icon.jpg" width="16" height="14" alt="" />Like:<a href="#">15</a></li>
                        <li ><img src="images/reply-icon.jpg" width="16" height="14" alt="" /><a href="javascript:voide(0);" id="reply_area">Reply:</a></li>

                    </ul>
                </div>
        </div>

        </div>
            <div id="reply">
          <div id="replys<?php echo$comment_id;?>">
        <?php
        $get_reply=mysql_query('select * from replys where comment_id ="'.$comment_id.'"');
        while($reply=mysql_fetch_array($get_reply))
        {
        $ruid=$reply['uid'];
        $replyx=$reply['reply'];
$get_user=mysql_query('select * from users where id ="'.$ruid.'"');
        $replyr=mysql_fetch_array($get_user);

        $rname=$replyr['user_name'];
        $rimage=$replyr['thumb'];
        if(strpos($rimage,'https://') !== false) {
$rthmbs=$rimage;
}else
{
$rthmbs='images/thumbs/'.$rimage;
}


    ?>          
       <div class="user-comment">
        <h2 style="font-size:15px;"><a style="color: rgb(5, 41, 84);text-decoration:none;" href="profile.php?id=<?php echo$ruid;?>"><?php echo $rname;?></a></h2>
      <br />
        <p style="margin:10px auto auto auto;position:relative;left:-10px;"><?php echo $replyx;?></p>
        <a style="color: rgb(5, 41, 84);text-decoration:none;" href="profile.php?id=<?php echo$ruid;?>"><img src="<?php echo$rthmbs;?>" width="51" height="56" alt="" /></a>
        <div class="user-comment-stuff">
            <div class="user-comment-stuff">
                    <ul>
                        <li ><img src="images/likes-icon.jpg" width="16" height="14" alt="" />Like:<a href="#">15</a></li>
                    </ul>
                </div>
        </div>

        </div>

        <?php
        }
        ?>
        </div>

            <form method="post" action="#">
        <textarea name="reply" class="reply" id="reply_input" placeholder="Reply On This Comment"></textarea>
        <input type="hidden" class="bid" name="bid" value="<?php echo $_GET['id'];?>">
        <input type="hidden" class="comment_id" name="comment_id" value="<?php echo $comment_id;?>">
        <input type="hidden" class="owner" name="owner"  value="<?php echo $cuid;?>" />
        <input type="submit" id="reply_btn" class="reply_btn post_reply" name="" value="Post"/>
        </form>
        </div>

        <?php
        }
        ?>
                </div>
用户评论

似乎
返回false导致问题

返回false调用时执行三件事:

  • event.preventDefault()
  • event.stopPropagation()
  • 停止回调执行并在调用时立即返回

  • 因此,如果
    返回false单击事件将不再触发。只需使用preventDefault()。

    您在
    sub\u comment.php
    文件中做什么?发送到数据库?我们能看到那个密码吗?另外,如果您已经有了
    preventDefault
    ,则不需要使用
    return false
    。是的,我尝试只使用return false,但不使用work。我不知道为什么在我发布回复时ajax显示文本区域为空,在我发布第一条评论检查编辑问题时我发布了所有代码在ajax完成后您正在执行
    $(.reply”).val(“”)@FouadFodail yeh,但如果我删除此项,则没有工作。但我看到了这样的情况:当我删除这个文本区域时,保留最后一个文本。当我发布另一个重播时,然后tetxarea显示我与第一个cment一起使用的最后一个tetx,如下=>我发布第一个comemnt重播“文本”时,一个文本区域保留这个值。我发布了另一个coment重播。然后textarea post“text”是什么?当您第二次发布时是否执行了插入?好的,我尝试只使用return false,但没有工作,我将此数据发送到数据库中。同样附加到.replys,但问题是为什么文本区域在第二个coments replay中显示为空:'(ajax完成后,您正在执行
    $(“.reply”).val(“”);
    <?php
    include_once 'config.php';
    if(isset($_POST['reply'])){
    $reply=mysql_real_escape_string($_POST['reply']);
    $uid=mysql_real_escape_string($_SESSION['id_social_f']);
    $type='reply_post';
    $comment_id=mysql_real_escape_string($_POST['comment_id']);
    $bid=mysql_real_escape_string($_POST['bid']);
    $owner=mysql_real_escape_string($_POST['owner']);
    $get_user=mysql_query('select * from users where id ="'.$uid.'"');
            $replyr=mysql_fetch_array($get_user);
    
            $rname=$replyr['user_name'];
            $rimage=$replyr['thumb'];
            if(strpos($rimage,'https://') !== false) {
    $rthmbs=$rimage;
    }else
    {
    $rthmbs='images/thumbs/'.$rimage;
    }
    
    $like_type='replyed';
    mysql_query('insert into replys(reply,comment_id,bid,uid)values("'.$reply.'","'.$comment_id.'","'.$bid.'","'.$uid.'")');
    $reply_id=mysql_insert_id();
    mysql_query('INSERT INTO notification (uid,bid,type,liker_id) VALUES("'.$owner.'","'.$bid.'","'.$like_type.'","'.$uid.'")');
    mysql_query('INSERT INTO activity (uid,comment_id,type,bid,reply_id) VALUES("'.$uid.'","'.$comment_id.'","'.$type.'","'.$bid.'","'.$reply_id.'")');
    ?>
       <div class="user-comment">
            <h2 style="font-size:15px;"><a style="color: rgb(5, 41, 84);text-decoration:none;" href="profile.php?id=<?php echo$uid;?>"><?php echo $rname;?></a></h2>
          <br />
            <p style="margin:10px auto auto auto;position:relative;left:-10px;"><?php echo $reply;?></p>
            <a style="color: rgb(5, 41, 84);text-decoration:none;" href="profile.php?id=<?php echo$ruid;?>"><img src="<?php echo$rthmbs;?>" width="51" height="56" alt="" /></a>
            <div class="user-comment-stuff">
                <div class="user-comment-stuff">
                        <ul>
                            <li ><img src="images/likes-icon.jpg" width="16" height="14" alt="" />Like:<a href="#">15</a></li>
                        </ul>
                    </div>
            </div>
    
            </div>
    <?php
    
    }
    ?>