我对HTML和PHP非常熟悉,但对jQuery和Ajax非常熟悉。
搜索了一段时间后,就像这里一样:一个表单,一个提交按钮,但两个操作和这里:写入我的数据库并使用相同的表单向PayPal提交表单?,我仍然对必须写入我的 HTML 文件的 eaxact 代码感到困惑。
我想做的是只需单击"提交"按钮,发送一封包含用户输入的数据的电子邮件(通过"保留.php"文件),并将用户发送到PayPal付款页面。
很抱歉再次提出同样的问题,但我结合这里和其他地方提出的不同解决方案所做的每一次尝试都让我一无所获。
这是我简化的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>
不确定为什么要这样做,如果您想在付款确认后向买家发送电子邮件并提供所有必要的信息,我建议您使用 IPN(即时付款通知)。