我有一个情况听到。我正在使用ajax从远程data.php页面加载mysql记录。它获取所有记录并完美显示在user.php的页面上。
现在每个记录都有评论选项,例如facebook。当我发表评论时,它应该将包含ID,评论文本和评论ID的表单数据发送到comment.php页面。为此,我正在使用ajax发送以下数据是我的ajax
$(function(){
$(document).on('submit','.comment_p',function(e){
e.preventDefault();
var com_dis= $("#comment_disc").val();
if(com_dis=='')
{
alert('Please add your comment');
} else{
$.ajax({
type:"POST",
url:"/comment_update.php",
data:$(this).serialize(),
success: function(data){
alert(data);
}
});
}
return false;
});
});
和示例图片
现在我的问题是,如果我在最后一条记录上发表评论,然后在与其他记录一起正常工作后发表评论。
但是在页面加载时,如果我直接发布其他评论,则最后记录其未将数据发布到php页面。
如果至少有一次我在最后一条记录上发表评论,那么它可以与其他记录一起工作。我感到很奇怪。
下面是我的远程加载记录的php页面形式。
<form method="post" id="'.$row['id'].'" class="comment_p">
<input id="post_id" type="hidden" name="post_id" value="'.$row['id'].'">
<textarea id="comment_disc" name="comment_disc" rows="2" cols="48"></textarea>
<button id="com_submit" type="submit" class="btn btnbg">Post comment</button>
<button type="reset" class="[ btn btn-default ]">Cancel</button>
</form>
我希望你明白。
改变:
var com_dis= $(this).find("#comment_disc").val();
注意:编号在页面上应该是唯一的
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句