En los envíos de respuesta, solo funciona la respuesta del primer comentario.
Frecuentes
Visto 99 veces
0
I am working a big project. I am getting stuck at making comment reply system. It works fine with Ajax but when I post second or another comment reply then text-area shows empty. Why is only the 1st reply submitted successfully? Here is my code:
$(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;
});
});
and here is whole code of comment system..
<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>
and bellow is 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 Respuestas
0
Parece que return false;
causar el problema
return false;
do three things when called :
- event.preventDefault ();
- event.stopPropagation ();
- Detiene la ejecución de la devolución de llamada y regresa inmediatamente cuando se llama.
Así que si usted return false;
the click event will never fire again. Just use preventDefault().
Respondido el 10 de Septiembre de 13 a las 00:09
ok i try only use return false but no work i send this data into data base. also append to .replys but problem is why text area show empty in second coments replay :' ( - user2738374
After ajax complete you are executing $(".reply").val('');
. - fouad Fodail
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas javascript jquery ajax or haz tu propia pregunta.
¿Qué estás haciendo en tu
sub_comment.php
file? Sending to database? Can we see that code? Also,return false
shouldn't be needed if you already havepreventDefault
. - Jordanyeh i try to use only return false but no work i donw know why ajax show textarea empty when i post reply exept 1st comment check edit quesiton i posted all code - user2738374
After ajax complete you are executing
$(".reply").val('');
. - Fouad Fodail@FouadFodail yeh but if i remove this no work. but i saw something like when i remov ethis textarea hold last text.and when i post another replay then tetxarea show this last tetx which i use with 1st cment like this=> i post 1st comemnt replay "text" thne text area hold this value. and i post another coment replay. then textarea post "text" what is it? - user2738374
Is the insert performed when you post for the second time? - Fouad Fodail