i have multiple forms with same class name
我有多个具有相同类名的表单
<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>
Then how can i submit a single form among this n number of forms i tried using
那么我怎样才能在我试过的n种表格中提交单一表格
$(function () {
$('form').on('submit', function (e) {
$.ajax({
type: 'post',
url: 'addfr.jsp',
data: $('form').serialize(),
success: function () {
location.reload();
}
});
e.preventDefault();
});
});
But it is submitting always 1st form among the n-forms. How can submit a random form among the n-forms. May any one help me please.
但它总是在n-forms中提交第一种形式。如何在n-forms中提交随机表格。愿任何人帮助我。
3 个解决方案
#1
13
You need to reference the form with this
when you serialize it...
您序列化时需要引用表单...
$(function () {
$('form').on('submit', function (e) {
$.ajax({
type: 'post',
url: 'addfr.jsp',
data: $(this).serialize(),
success: function () {
location.reload();
}
});
e.preventDefault();
});
});
#2
1
Use this keyword. It will submit the form on which the event has been triggered.
使用此关键字。它将提交触发事件的表单。
why are u using location.reload?
你为什么使用location.reload?
$('form').on('submit', function (e) {
$.ajax({
type: 'post',
url: 'addfr.jsp',
data: $(this).serialize(),
success: function () {
location.reload();
}
});
#3
0
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>
#1
13
You need to reference the form with this
when you serialize it...
您序列化时需要引用表单...
$(function () {
$('form').on('submit', function (e) {
$.ajax({
type: 'post',
url: 'addfr.jsp',
data: $(this).serialize(),
success: function () {
location.reload();
}
});
e.preventDefault();
});
});
#2
1
Use this keyword. It will submit the form on which the event has been triggered.
使用此关键字。它将提交触发事件的表单。
why are u using location.reload?
你为什么使用location.reload?
$('form').on('submit', function (e) {
$.ajax({
type: 'post',
url: 'addfr.jsp',
data: $(this).serialize(),
success: function () {
location.reload();
}
});
#3
0
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>