将表单值发送到多个页面 [英] send the form values to multiple pages

查看:58
本文介绍了将表单值发送到多个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个网络应用程序,我需要将值从一个表单发送到多个页面.

I am working on a web application where I need to send the value from one form to more than one page.

我的表格很简单:

<form method="post">
    <input type="text" name="name" value="">
    ...
</form>

我希望将表单中的值发送到:

I want the values from the form to be sent to :

  • 'page1.php' 将替换包含显示消息的表单的实际页面:数据已保存
  • 'page2.php' 当我点击提交按钮将数据呈现为 PDF 文件时会打开

问题是我只能使用表单的 action 属性指定一个目标.

The problem is that I can only specify only one target using the action attribute of the form.

任何人都可以帮忙吗?提前致谢.

Anyone can helps ? Thanks in advance.

我可以使用 JavaScript 或 jQuery 或其他吗?

Could I use JavaScript or jQuery or other ?

推荐答案

例如,您可以使用 JavaScript 和 jQuery 来完成.最简单的方法是发送两个ajax请求:

You can do it using JavaScript and jQuery for example. The easiest way is send two ajax requests:

$('form').submit(function() {
    $.ajax({
        async: false,
        method: 'POST',
        url: 'page2.php',
        data: $( this ).serialize(),
        success: function() {
             window.open("http://www.stackoverflow.com"); //this page will be open in new tab
        }
    });

    $.ajax({
        async: false,
        method: 'POST',
        url: 'page1.php',
        data: $( this ).serialize(),
        success: function() {
            window.location.href = "http://stackoverflow.com"; //redirect to this page
        }
    });
});

这篇关于将表单值发送到多个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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