如何在手动表单提交中添加post参数?
我想在经过一些复杂的检查后手动提交表格。由于检查涉及用户交互,因此整个检查过程不是同步完成的。以下是场景:
- 用户单击按钮(HTML
- 我阻止按钮的默认操作(即表单提交)
- 我执行一项复杂的检查。
- 在检查过程中的某个地方,我显示一个对话框并等待用户响应(这里,原始检查函数继续并返回)
- 我为该对话框提供了一个回调函数,该函数在用户关闭它时触发并运行(无论是正数还是 负数)否定结果)
- 现在,我应该提交表单,但原始 HTML
我使用 jQuery 的 $('#form-id').submit()
方法。如何将
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:
- 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.
I use jQuery's $('#form-id').submit()
method. How can I add the name
of the <button>
element to the HTTP Post parameters?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在提交之前将隐藏字段附加到表单中 -
You could append a hidden field to your form before submitting -
与其使用按钮类型,为什么不使用
Instead of using a button type, why not use