需要将单个表单发布到两个不同的页面

时间:2015-05-20 14:51:25

标签: php jquery ajax

我试图将单个表单发布到两个页面。第一页是loacally托管,另一页是远程页面,需要在发布到第一页后重定向。我可以使用jquery发布表单,但不知道如何发布到远程服务器的文件。

我的表格如下:

<form method ='POST' action='https://remotewebsite.com/api/step1.asp' id='payment_form' class='form-horizontal' >
    <div class='form-body'>
        <input type='hidden' name='group' value='$net_amount'/>
        <input type='hidden' name='type' value='$payment_type' />

        <div class='modal-footer'>
            <button type='button' class='btn default' data-dismiss='modal'>Cancel</button>
            <input type='button' id='pay' name='pay' value='pay' class='btn green' />                       
        </div>  
    </div>
</form>

我可以使用jquery将其发布到我的其他页面上说&#34; process.php&#34;但无法找到任何方式将表单再次提交到网址https://remotewebsite.com/api/step1.asp

<script type="text/javascript">
    $('input[type=button]').click(function(e){
        e.preventDefault(); // prevent the browser's default action of submitting 
            $.ajax({
                type: "POST",
                url: "process.php",
                data=$("#payment_form").serialize(),
                data: data,
                dataType: "html",
            });
    });
</script>

2 个答案:

答案 0 :(得分:1)

一种解决方案是按照您目前的方式POST到process.php脚本。

然后,在您完成处理后,将cURL POST请求发送到远程服务器(来自您的process.php脚本。如果您是Google PHP curl post request,您应该找到加载文章告诉您如何操作,例如:http://davidwalsh.name/curl-post

答案 1 :(得分:1)

如何简单地复制$ .ajax?

<script type="text/javascript">
$('input[type=button]').click(function(e){
    e.preventDefault(); // prevent the browser's default action of submitting 
        $.ajax({
            type: "POST",
            url: "process.php",
            data=$("#payment_form").serialize(),
            data: data,
            dataType: "html",
        });
        $.ajax({
            type: "POST",
            url: "https://remotewebsite.com/api/step1.asp",
            data=$("#payment_form").serialize(),
            data: data,
            dataType: "html",
        });
});
</script>