【发布时间】: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