使用jquery ajax在多个表单中提交表单
我有多个相同类名的表单使用jquery ajax在多个表单中提交表单,ajax,forms,jquery,multiple-forms,Ajax,Forms,Jquery,Multiple Forms,我有多个相同类名的表单 <form > <input type="hidden" value="<%=ids%>" name="idd"> <input type="hidden" value="<%=email%>" name="cby"> <input type="text" class="cmd" name="cm" style="width:300px;" placeholder="comment">
<form >
<input type="hidden" value="<%=ids%>" name="idd">
<input type="hidden" value="<%=email%>" name="cby">
<input type="text" class="cmd" name="cm" style="width:300px;" placeholder="comment">
<input type="submit" value="" style="display:none;">
</form>
<!-- n number of forms are generated using while loop-->
<form>
<input type="hidden" value="<%=ids%>" name="idd">
<input type="hidden" value="<%=email%>" name="cby">
<input type="text" class="cmd" name="cm" style="width:300px;" placeholder="comment">
<input type="submit" value="" style="display:none;">
</form>
但它总是提交n个表格中的第一个表格。
如何在n个表单中提交随机表单。
任何人都可以帮助我。在序列化表单时,您需要使用
此
引用该表单
$(function () {
$('form').on('submit', function (e) {
$.ajax({
type: 'post',
url: 'addfr.jsp',
data: $(this).serialize(),
success: function () {
location.reload();
}
});
e.preventDefault();
});
});
使用这个关键字。它将提交触发事件的表单 为什么要使用location.reload
$('form').on('submit', function (e) {
$.ajax({
type: 'post',
url: 'addfr.jsp',
data: $(this).serialize(),
success: function () {
location.reload();
}
});
你可以试试这个。。。
函数submitForm(){
document.formName.action=“actionName”;
document.formName.submit();
}
....
+1比我快了半秒,但这似乎是问题所在,每次触发其中一个表单上的提交事件时,都会序列化所有表单。@adeneo您需要充分润滑才能在该站点上足够快,不是吗!只要他们得到答案:)$(这个)。serialize()
在ajax
中可能不起作用,所以你应该为这个引用使用一个变量,然后使用它。@RohanKumar-没有新的作用域,所以这个
会很好地工作。@HarikaChoudaryKanikanti“不起作用”是什么意思?到底发生了什么?同一类型的问题
$('form').on('submit', function (e) {
$.ajax({
type: 'post',
url: 'addfr.jsp',
data: $(this).serialize(),
success: function () {
location.reload();
}
});
You can try this...
function submitForm(){
document.formName.action="actionName";
document.formName.submit();
}
<form method="post" name="formName" enctype="multipart/form-data">
....
<input type="button" onclick="submitForm()"/>
<form>