【问题标题】:submit both a paypal form and a php form with the same button, using jquery & ajax使用 jquery 和 ajax 提交具有相同按钮的 paypal 表单和 php 表单
【发布时间】:2015-01-22 15:34:06
【问题描述】:

我对 HTML 和 PHP 非常熟悉,但对 jQuery 和 Ajax 非常陌生。

经过一段时间的搜索,比如这里:One form, One submission button, but TWO actions 和这里:Writing to my DB and submitting a form to Paypal using the same form?,我仍然对必须写入 HTML 文件的确切代码感到困惑。

我想要做的是只需单击“提交”按钮,发送一封包含用户输入数据的电子邮件(通过“reserve.php”文件) 将用户发送到贝宝付款页面。

很抱歉再次问同样的问题,但我每次尝试结合这里和其他地方提出的不同解决方案都让我一无所获。

这是我的简化 HTML 代码:

<html>
<head>
    <title>Bienvenue Telecom</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <link rel="shortcut icon" type="image/x-icon" href="/images/favicon.ico" />
    <!--[if lte IE 8]><script src="css/ie/html5shiv.js"></script><![endif]-->
    <script src="js/jquery.min.js"></script>
    <script src="js/jquery.scrolly.min.js"></script>
    <script src="js/skel.min.js"></script>
    <script src="js/init.js"></script>
    <noscript>
        <link rel="stylesheet" href="css/skel.css" />
        <link rel="stylesheet" href="css/style.css" />
        <link rel="stylesheet" href="css/style-desktop.css" />
    </noscript>

<!-- Here is the function I tried to make myself to submit the same form both to paypal and to the reserve.php -->

<script>
        $(document).ready(function doublesubmit() {
                $.ajax({url: "https://www.paypal.com/cgi-bin/webscr", data: ("form").serialize(), type : "POST", success: function(){
                        $.ajax({url: "reserve.php", data: $("form").serialize(), type : "POST",
                        }
                    });         
                };
            return false;
        };
    </script>
</head>

<!-- Here is the body of my page, with the only form the user has to fill in -->

<body>
    <form id="form" target="_blank" method="post">
<input type="hidden" name="business" value="XXXXXXXX">

<!-- many other hidden and visible input values -->

<input type="submit" value="Send request" name="submit" border="0" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" alt="PayPal - The safer, easier way to pay online" onclick="doublesubmit();">
</form>
</body>
</html>

【问题讨论】:

    标签: javascript php jquery ajax paypal


    【解决方案1】:

    不知道为什么要这样做,如果您想在付款确认后向买家发送包含所有必要信息的电子邮件,我建议您使用IPN(即时付款通知)。

    【讨论】:

    • 这封邮件是给我的,它的目的是从没有经历整个paypal流程的客户那里获取信息。在客户关闭贝宝窗口的情况下,我将无法获得他在我的网站上发布的任何信息,因为 IPN 仅在客户实际完成付款过程时才有用。这就是为什么我需要一键提交 2 次。
    • 这种情况下,你可能需要先发邮件,然后发起paypal交易。我会用jquery ajax调用php文件发邮件,发邮件后,调用paypalpaypal.com/cgi-bin/webscr.Becasue这个函数 $.ajax({url: "paypal.com/cgi-bin/webscr", data: ("form").serialize(), type : "POST", success: function(){ 不会返回success
    • 感谢您的回答。如果我翻译你在这段 js 代码中所说的话,我是否正确(这只是两个 ajax post 函数的反转):? ' $(document).ready(function doublesubmit() { $.ajax({url: "reserve.php", data: $("form").serialize(), type : "POST", success: function() { $.ajax({url: "paypal.com/cgi-bin/webscr", data: $("form").serialize(), type : "POST", } }); }; return false; };'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-20
    • 2012-04-04
    • 2013-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多