gpt4 book ai didi

javascript - 在php中执行一个php函数

转载 作者:行者123 更新时间:2023-11-29 04:40:40 26 4
gpt4 key购买 nike

在下面的脚本中,一旦用户单击提交按钮并且没有出现错误,就会生成一个包含 token 值的输入。然后我想将该值发布到 php 页面内,以便我可以在我的查询中使用它。这里输入值已成功生成,但将其值发布到 php 页面并执行 php 页面是问题所在(我在下面详细说明)下面是脚本:

 <script type="text/javascript">
// This identifies your website in the createToken call below
Stripe.setPublishableKey('code');

var appendedStripeToken = false;

var stripeResponseHandler = function(status, response) {
var $form = $('#payment-form');

if (response.error) {
// Show the errors on the form
$form.find('.payment-errors').text(response.error.message);
$form.find('button').prop('disabled', false);

} else {
// token contains id, last4, and card type
var token = response.id;
handleCall(token);
}
};

function handleCall(token) {
var $form = $('#payment-form');
if (!appendedStripeToken) {
// Insert the token into the form so it gets submitted to the server
$form.append($('<input type="text" name="stripeToken" />').val(token));
appendedStripeToken = true;
phpCall();

}
}

function onSubmit() {
var $form = $('#payment-form'); // TODO: give your html-form-tag an "id" attribute and type this id in this line. IMPORTANT: Don't replace the '#'!

// Disable the submit button to prevent repeated clicks
// TODO: give your html-submit-input-tag an "id" attribute

Stripe.card.createToken($form, stripeResponseHandler);
}


function phpCall() {
if( appendedStripeToken === true ){
$.ajax({
type: "POST",
data: {run: true},
url: 'functions/paymentEmail.php',
success: function (response) {//response is value returned from php (for your example it's "bye bye"
$('#payment-form').prop('disabled', true); // TODO: give your html-submit-input-tag an "id" attribute

alert(response);
}
});
}
}
</script>

现在具体看一下这部分

url: 'functions/paymentEmail.php',
success: function (response) {//response is value returned from php (for your example it's "bye bye"
$('#payment-form').prop('disabled', true); // TODO: give your html-submit-input-tag an "id" attribute

alert(response);

我不希望执行带有警告框的 php 函数,因为它不会运行。 enter image description here

下面是php代码:

     <?php


$course_price_final = $_POST['course_price_final'];
$course_token = $_POST['stripeToken'];
$course_provider = $_POST['course_provider'];
$user_email = $_POST['user_email'];
$course_delivery = $_POST['course_delivery'];
$order_date = date("Y-m-d");
$insert_c = "insert into orders (course_title,course_price_final,course_provider,user_email,course_date,course_delivery,order_date,course_token)
values ('$crs_title','$course_price_final','$course_provider','$user_email','$course_date1','$course_delivery','$order_date','$course_token')";
$run_c = mysqli_query($con, $insert_c);

$location = "../paymentConfirmed.php";


header( "Location: $location" );

?>

最佳答案

如果您想使用 ajax 进行重定向,您可以返回一个 url,而不是创建一个 window.location = response

关于javascript - 在php中执行一个php函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29709513/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com