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

时间:2013-09-09 22:47:20

标签: javascript jquery ajax

我正在做一个大项目。我正在制作评论回复系统。它适用于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>

和bellow是sub_comemnt.php

<?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

}
?>

1 个答案:

答案 0 :(得分:0)

return false;似乎导致问题。

return false;在调用时做三件事:

  1. event.preventDefault();
  2. event.stopPropagation();
  3. 停止回调执行并在调用时立即返回。
  4. 因此,如果您return false;,点击事件将永远不会再次触发。只需使用preventDefault()。