两种形式,一种提交-提交,延迟,提交 [英] Two forms one submit - Submit, delay, submit

查看:152
本文介绍了两种形式,一种提交-提交,延迟,提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图同时提交两种形式(一种去db,另一种去fpdf来制作标签).我使用jquery将变量从第一种形式复制到第二种形式的隐藏输入中.我在这里看到几次问过这个问题,但没有一个答案有帮助.我使用'fake'ajax方法-即:我将表单目标设置为同一页面上的隐藏iframe.所以我想提交一种形式,然后使用延迟,然后提交第二种形式(因为没有延迟,它是行不通的!)

I am trying to submit two forms at once (one goes to db and the other goes to fpdf to make labels). I use jquery to copy the variables from the first form to hidden inputs on the second form. I have seen this question asked a couple times on here but none of the answers have helped. I use the 'fake' ajax method - ie: I set the form target to a hidden iframe on the same page. So I want to submit one form, then use a delay then submit the second form (because it's not working without the delay!)

那么我该如何在这段代码中添加延迟:

So how do I add a delay to this code:

    $('#insert').submit(function() {
    //Delay here please, or is it timeout I need?
    $('#print').submit();
    });

<form id="insert" action="insert.php" target="hiddeniframe">
// a bunch of inputs
<input type="submit" value="submit">
</form>

<form id="print" action="pdf.php" target="hiddeniframe">
// a bunch of inputs
</form>

推荐答案

目前尚不清楚您的脚本在做什么/返回什么,但是您始终可以将ajax用于第一个请求,然后将iframe用于第二个请求.例如:

It's not clear on what your scripts are doing / returning, but you can always use ajax for the first request, then use the iframe for the second request. Eg:

$('#insert').on('submit', function(e) {
  e.preventDefault();

  $.ajax({
    url: $(this).attr('action'),
    type: 'POST',
    data: $(this).serialize(),
    success: function() {
      // duplicate fields from first form into second form
      // as per whatever code you've already written

      // submit second form
      $('#print').submit();
    })
  });
});

通过这种方式,第二个表单在第一个表单的成功响应之后被提交.

This way the second form is submitted after the successful response of the first form.

这篇关于两种形式,一种提交-提交,延迟,提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆