2014-11-24 15 views
0

我對HTML和PHP非常熟悉,但是在jQuery和Ajax中真是新手。使用jquery&ajax提交一個paypal表單和一個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文件的eaxact代碼混淆。

我想要做的就是與「提交」按鈕只有一個點擊,發送與用戶輸入的數據電子郵件(通過「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> 

回答

0

不知道爲什麼你要做這樣一來,如果你想發送電子郵件給買家與在支付確認所有必要的信息,我建議你使用IPN(即時付款通知)。

+0

這封電子郵件是給我的,其目的是從沒有通過整個PayPal流程的客戶那裏獲取信息。在客戶關閉PayPal窗口的情況下,我將無法獲得他在我的網站上發佈的任何信息,因爲當客戶實際完成支付流程時,IPN只是有用的。這就是爲什麼我需要點擊兩次提交。 – 2014-11-25 10:06:02

+0

這種情況下,您可能首先需要發送電子郵件,然後啓動PayPal交易。我只需使用Jquery ajax調用一個php文件發送電子郵件,然後在發送電子郵件時,致電Paypal https://www.paypal.com/。 cgi-bin/webscr.Becasue這個函數$ .ajax({url:「https://www.paypal.com/cgi-bin/webscr」,data:(「form」)。serialize(),type:「POST 「,success:function(){不會返回成功' – Vimalnath 2014-11-25 10:48:44

+0

感謝您的回答。所以我正確的,如果我翻譯你在這個js代碼中說過的話(它只是兩個ajax post函數的反轉) :?\t \t \t $(文件)。就緒(函數doublesubmit(){ \t \t \t \t \t $阿賈克斯(網址:{url: 「reserve.php」 數據:$( 「形式」)序列化()鍵入:「POST」, \t \t \t \t \t \t成功:函數(){ \t \t \t \t \t \t \t $阿賈克斯(網址:{url: 「https://www.paypal.com/cgi-bin/webscr」 數據:$( 「形式」)序列(),類型: 「POST」, \t \t \t \t \t \t \t} \t \t \t \t \t \t});。 \t \t \t \t \t \t \t \t}; \t \t \t \t return false; \t \t \t};' – 2014-11-25 11:30:34