【发布时间】:2015-03-25 21:18:33
【问题描述】:
我有一个 php 脚本,它为支付系统的信用卡收费,但问题是我有一个脚本,其中包含一个变量,我试图在每次调用 php 脚本中的函数时将 1 添加到,唯一的问题是它不起作用。我不确定代码是否有问题,或者是因为在加载新页面时没有保存变量,因为每次调用 php 脚本时它都会重定向到新页面。
带有名为product1.html的变量的html脚本
<script type="text/javascript">
var currentBid = 1;
document.getElementById("currentBid").innerHTML = currentBid;
function addOne() {
currentBid = currentBid +1;
document.getElementById("currentBid").innerHTML = currentBid;
}
</script>
带有chargeCard.php函数的php脚本
<?php
require_once('./stripe-php/init.php');
// Set your secret key: remember to change this to your live secret key in production
// See your keys here https://dashboard.stripe.com/account
\Stripe\Stripe::setApiKey("Removed for safety");
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
$myAmount = $_POST['amount'];
$describtion = $_POST['description'];
$myAmount = round((int)$myAmount*100,0);
// Create the charge on Stripe's servers - this will charge the user's card
try {
$charge = \Stripe\Charge::create(array(
"amount" => $myAmount, // amount in cents, again
"currency" => "usd",
"source" => $token,
"description" => $describtion));
echo '<script type="text/javascript">addOne();</script>"';
} catch(\Stripe\Error\Card $e) {
// The card has been declined
}
?>
我试图在 php 脚本中调用的函数是 echo '<script type="text/javascript">addOne();</script>"'; 这一行
【问题讨论】:
-
按 f12 并重新加载页面。控制台中的任何错误? php 脚本与 product1.html 的关系有多远?你的php脚本是怎么调用的?
-
我可能认为这是问题所在,因为它与我用来调用 chargin 函数的脚本相同,但我没有做任何事情来将脚本与 javascript 函数连接起来,这可能是它不起作用的原因吗?
-
PHP 是如何进入页面的......?这两个文件是分开调用的吗? -- 在这种情况下它永远不会起作用。
-
是的,它们是两个独立的文件。
标签: javascript php html variables addition