Javascript Onclick函数
我已经在谷歌上搜索过了,论坛上没有人和我一样 我解释一切: 代码来源:Javascript Onclick函数,javascript,onclick,Javascript,Onclick,我已经在谷歌上搜索过了,论坛上没有人和我一样 我解释一切: 代码来源: <!DOCTYPE html> <html> <head> <title>cc</title> </head> <body> <script src="<a href="https://code.jquery.com/jquery-3.1.1.js" rel="nofollow">https://code.jquery.
<!DOCTYPE html>
<html>
<head>
<title>cc</title>
</head>
<body>
<script src="<a href="https://code.jquery.com/jquery-3.1.1.js" rel="nofollow">https://code.jquery.com/jquery-3.1.1.js</a>" integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA=" crossorigin="anonymous"></script>
<form target="id.php" method="post">
<button name="purchase" onclick="purchase('19d9309b6091', 'eth');">ETH</button>
<button name="purchase" onclick="purchase('19d9309b6091', 'btc');">BTC</button>
<button name="purchase" onclick="purchase('19d9309b6091', 'paypal');">Paypal</button>
<button name="purchase" onclick="purchase('19d9309b6091', 'pm');">Perfect Money</button>
<script type="text/javascript">
function purchase(productId, paymentMethod) {
let coupon = $('#coupon').val();
$('#purchaseContainer').hide();
$('#purchaseContainerError').text('').hide();
$.post('', {
purchase: "1",
paymentMethod: paymentMethod,
productId: productId,
coupon: coupon
}).done(function(data) {
json = JSON.parse(data);
console.log(json) if (json.error) {
$('#purchaseContainer').show();
$('#purchaseContainerError').text(json.error).show();
return;
} else {
if (json.urlToRedirect) {
$('#purchaseCompletedContainer').html('Redirecting you to paypal').show();
window.location.href = json.urlToRedirect;
} else if (json.form) {
$('#purchaseCompletedContainer').html(json.form).show();
} else {
let html = 'To complete the purchase, please send <code>' + json.amount + '</code> to <code>' + json.address + '</code>';
$('#purchaseCompletedContainer').html(html).show();
}
}
});
}
</script>
</form>
</body>
</html>
第页PHP:
<?php
$email = '***@****.com';
if(isset($_POST['purchase']) && isset($_POST['paymentMethod']) && isset($_POST['productId'])) {
$paymentMethod = filter_var($_POST['paymentMethod'], FILTER_SANITIZE_STRING);
$productId = filter_var($_POST['productId'], FILTER_SANITIZE_STRING);
if(isset($_POST['coupon']))
$coupon = filter_var($_POST['coupon'], FILTER_SANITIZE_STRING);
else
$coupon = '';
$postData = [
'product_id' => $productId,
'purchase' => "1",
'method' => $paymentMethod,
'email' => $email,
'coupon_code' => '',
'quantity' => '1',
'applicationID' => '10',
'applicationSecret' => 'B346C3F5B879EBA4E6AC5A2D7ED9843DF',
'customerIP' => $_SERVER['REMOTE_ADDR']
];
$ch = curl_init('<a href="https://*****.net/*****.php" rel="nofollow">https://*****.net/*****.php</a>');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$response = curl_exec($ch);
curl_close($ch);
if($response !== false){
die($response);
} else {
die(json_encode(['error' => 'Error Creating Order']));
}
}
?>
请帮帮我。这个:
}).done(function(data) {
json = JSON.parse(data);
console.log(json) if (json.error) {
$('#purchaseContainer').show();
应该是:
}).done(function(data) {
json = JSON.parse(data);
console.log(json);
if (json.error) {
$('#purchaseContainer').show();
您删除了console.log(json)后面的分号 哈哈,很简单
只需在购买前添加:
javascript:
。您实际上还没有问过任何问题。你的代码有什么问题?请在问题中直接阅读并包含所有相关信息。请将相关代码和错误作为文本而不是图片。