我正在尝试使用Ajax发送表单数据。使用远程页面的ajax提取记录后,将显示我的索引页面。
下面是我的页面图像。
每个记录都有注释框,我想使用ajax将这些注释存储在数据库中。
下面是我的jQuery
$(function(){
$('body').on('submit','.comment_p',function(){
var post_id = $("#post_id").val();
var com_dis= $("#comment_disc").val();
var cominfo = 'id=' + post_id + '&disc=' + com_dis;
if(com_dis=='')
{
alert('Please add your comment');
} else{
$.ajax({
type:"POST",
url:"/comment_update.php",
data:$(".comment_p").serialize(),
success: function(data){
alert(data);
}
});
}
return false;
});
});
我单击时使用
body
,因为这些记录是从远程页面加载的。我的表格如下
<div class="panel-zesteve-textarea">
<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>
现在,当我单击发布时,评论正在处理最后一条记录。我需要发送身份证号。和textarea值到php页面以在mysql中更新,但是两个注释都显示相同的记录ID和注释。它不适用于第二个
最佳答案
尝试使用$(this)
引用表单
data: $(this).serialize(), instead of `data:$(".comment_p").serialize(),`
关于php - 从ajax加载的记录发送表单数据到php,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36526308/