I have tried multiple ways of doing this, by searching on * for the answer.
我尝试了多种方法,通过在*上搜索答案。
I have two forms
我有两种形式
Form 1 basic setup:
形式1基本设置:
<form action="/post" class="frm-form" method="post" name="post"
onsubmit="return vB_Editior['text_editor'].prepare_submit(0,0)" id="quick_reply">
<textarea></textarea>
<input type="submit" name="post" value="Send">
</form>
Form 2 basic setup:
表格2基本设置:
<form enctype="multipart/form-data" id="tagnotif" style="display:none;"
onsubmit="return vB_Editor['text_editor'].prepare_submit(0,0)" name="post2"
method="post" action="/privmsg">
<input id="username" class="post" type="text" tabindex="1" size="25"
name="username[]"style="margin:1px 0"><br />
<input id="acpro_inp10" class="post" type="text"
onkeypress="if (event.keyCode==13){return false}" title="" tabindex="2"
maxlength="64" size="45" value="You have been tagged" name="subject"><br />
<textarea id="textingnotification" rows="15" cols="9"
name="message" tabindex="3"></textarea>
<input type="hidden" value="" name="lt">
<input type="hidden" value="inbox" name="folder">
<input type="hidden" value="post" name="mode">
</form>
I just need these two forms to be submitted on SEND press of first form
我只需要这两份表格在发送第一份表格时提交
TRIED USING THIS CODE VARIABLES WITH THE MAIN SCRIPT: Though it won't pass both, and it won't refresh the page...
尝试使用主脚本的代码变量:尽管它不会同时传递这两个变量,也不会刷新页面……
$(document).ready(function() {
$('#quick_reply').ajaxForm(function() {
alert("Thank you for your submitting form 1");
});
$('#tagnotif').ajaxForm(function() {
alert("Thank you for your submitting form 2");
});
});
function mySubmitFunction() {
$("#quick_reply").submit();
$("#tagnotif").submit();
}
2 个解决方案
#1
4
I don't think you can do two regular post requests from a single html page, because making the post involves leaving the page and following the redirect response.
我认为您不可能在一个html页面中执行两个常规的post请求,因为创建post需要离开页面并遵循重定向响应。
If you're submitting the forms via ajax, why not just make a single ajax button and grab the needed parameters to stick in the request? IE:
如果您正在通过ajax提交表单,那么为什么不创建一个ajax按钮并获取所需的参数以插入请求呢?即:
$.ajax({
type: 'POST',
dataType: 'JSON',
data: {param1: $('input#param1').val(), param2: $('input#param2').val()},
url: 'url to post to',
success: (your success callback function goes here)
})
#2
1
Doing this first you need to remove every submit buttons from these two forms If form have submit button this won't work.
首先,如果表单有提交按钮,则需要从这两个表单中删除每个提交按钮。
First Form
第一个表格
<form action="/post" id="frm-form" class="frm-form" method="post" name="post"
onsubmit="return vB_Editior['text_editor'].prepare_submit(0,0)" id="quick_reply">
<textarea></textarea>
<input id="frm-submit" type="button" name="post" value="Send">
</form>
Second Form
第二种形式
<form enctype="multipart/form-data" id="tagnotif" style="display:none;"
onsubmit="return vB_Editor['text_editor'].prepare_submit(0,0)" name="post2"
method="post" action="/privmsg">
<input id="username" class="post" type="text" tabindex="1" size="25"
name="username[]"style="margin:1px 0"><br />
<input id="acpro_inp10" class="post" type="text"
onkeypress="if (event.keyCode==13){return false}" title="" tabindex="2"
maxlength="64" size="45" value="You have been tagged" name="subject"><br />
<textarea id="textingnotification" rows="15" cols="9"
name="message" tabindex="3"></textarea>
<input type="hidden" value="" name="lt">
<input type="hidden" value="inbox" name="folder">
<input type="hidden" value="post" name="mode">
</form>
JQuery
JQuery
$("#frm-submit").change(function(){
$("#frm-form").submit();
$("#tagnotif").submit();
});
This will Refresh the page and submit two forms
这将刷新页面并提交两种表单。
#1
4
I don't think you can do two regular post requests from a single html page, because making the post involves leaving the page and following the redirect response.
我认为您不可能在一个html页面中执行两个常规的post请求,因为创建post需要离开页面并遵循重定向响应。
If you're submitting the forms via ajax, why not just make a single ajax button and grab the needed parameters to stick in the request? IE:
如果您正在通过ajax提交表单,那么为什么不创建一个ajax按钮并获取所需的参数以插入请求呢?即:
$.ajax({
type: 'POST',
dataType: 'JSON',
data: {param1: $('input#param1').val(), param2: $('input#param2').val()},
url: 'url to post to',
success: (your success callback function goes here)
})
#2
1
Doing this first you need to remove every submit buttons from these two forms If form have submit button this won't work.
首先,如果表单有提交按钮,则需要从这两个表单中删除每个提交按钮。
First Form
第一个表格
<form action="/post" id="frm-form" class="frm-form" method="post" name="post"
onsubmit="return vB_Editior['text_editor'].prepare_submit(0,0)" id="quick_reply">
<textarea></textarea>
<input id="frm-submit" type="button" name="post" value="Send">
</form>
Second Form
第二种形式
<form enctype="multipart/form-data" id="tagnotif" style="display:none;"
onsubmit="return vB_Editor['text_editor'].prepare_submit(0,0)" name="post2"
method="post" action="/privmsg">
<input id="username" class="post" type="text" tabindex="1" size="25"
name="username[]"style="margin:1px 0"><br />
<input id="acpro_inp10" class="post" type="text"
onkeypress="if (event.keyCode==13){return false}" title="" tabindex="2"
maxlength="64" size="45" value="You have been tagged" name="subject"><br />
<textarea id="textingnotification" rows="15" cols="9"
name="message" tabindex="3"></textarea>
<input type="hidden" value="" name="lt">
<input type="hidden" value="inbox" name="folder">
<input type="hidden" value="post" name="mode">
</form>
JQuery
JQuery
$("#frm-submit").change(function(){
$("#frm-form").submit();
$("#tagnotif").submit();
});
This will Refresh the page and submit two forms
这将刷新页面并提交两种表单。