如何将post参数添加到手动表单提交? [英] How to add a post parameter to manual form submission?
本文介绍了如何将post参数添加到手动表单提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在经过一些复杂的检查后手动提交表格。由于检查涉及用户交互,因此不会同步完成整个检查过程。以下是该场景:
I want to submit a form manually after some complicated checks. Because checks involve user interaction, the whole check process is not done synchronously. Here is the scenario:
- 用户点击一个按钮(HTML
< button id ='button-id' >
tag) - 我阻止按钮的默认操作(即表单提交)
- 我做的一个复杂的检查。
- 在检查过程中的某个地方,我显示一个对话框并等待用户响应(这里,原始检查功能继续并返回)
- 我为该对话框提供了一个回调函数,当用户关闭它时会激活并运行(正面或负面结果)
- 现在,我应该提交表单,但是原始HTML
< button id ='button-id'>
应张贴为成功控制。换句话说,我应该将按钮标记的名称
添加为服务器的已发布参数之一。
- User clicks a button (an HTML
<button id='button-id'>
tag) - I prevent the default action of the button (which is the form submission)
- I do a complicated check.
- Somewhere in the check process, I show a dialog and wait for the user to respond (here, the original check function proceeds and returns)
- I provide a callback function for that dialog, which fires and runs when the user closes it (either positive or negative result)
- Now, I should submit the form, but the original HTML
<button id='button-id'>
should be posted as a successful control. In other words, I should add thename
of the button tag as one of the posted parameters to the server.
我使用jQuery的 $('#form-id')。submit()
方法。如何将< button>
元素的名称
添加到HTTP Post参数?
I use jQuery's $('#form-id').submit()
method. How can I add the name
of the <button>
element to the HTTP Post parameters?
推荐答案
您可以在提交之前在表单中附加隐藏字段 -
You could append a hidden field to your form before submitting -
$('<input>').attr({
type: 'hidden',
id: 'buttonid',
name: 'buttonid',
value: yourbuttonidvar
}).appendTo('#form-id');
这篇关于如何将post参数添加到手动表单提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文