如何将post参数添加到手动表单提交?

编程入门 行业动态 更新时间:2024-10-26 01:27:38
本文介绍了如何将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 the name 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参数添加到手动表单提交?

    本文发布于:2023-10-10 22:46:51,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1479970.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:表单   如何将   参数   post

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!