Javascript 条带未重定向到签出页面

Javascript 条带未重定向到签出页面,javascript,php,html,Javascript,Php,Html,我正在重定向到pay.php并在pay.php中获得session.id,但我没有重定向到签出页面:( var checkburatton=document.getElementById(“paymentform”).submit() 我正在尝试重定向到签出页面我应该在条带中创建产品吗 在JavaScript代码中,在事件侦听器之前添加了一个.submit()。这会导致重定向页面而不提交信息。请检查以下代码 <html> <head> <script s

我正在重定向到pay.php并在pay.php中获得session.id,但我没有重定向到签出页面:(

var checkburatton=document.getElementById(“paymentform”).submit()

我正在尝试重定向到签出页面我应该在条带中创建产品吗



在JavaScript代码中,在事件侦听器之前添加了一个
.submit()
。这会导致重定向页面而不提交信息。请检查以下代码

<html>
<head>
    <script src="https://polyfill.io/v3/polyfill.min.js?version=3.52.1&features=fetch"></script>
    <script src="https://js.stripe.com/v3/"></script>
</head>
<?php if(isset($_POST['productname']) && $_POST['productname']!="" && isset($_POST['amount']) && $_POST['amount']!="")
{ ?>
    <form name="paymentform" class="paymentform" style="display:none" id="paymentform" method="post" action="pay.php">
        <input name="productname" type="hidden" value="<?=$_POST['productname'];?>">
        <input name="amount" type="hidden" value="<?=$_POST['amount'];?>">
    </form>
    <script type="text/javascript">
    // Create an instance of the Stripe object with your publishable API key
    var stripe = Stripe("pk_test_576576576576576");
    var paymentform = document.getElementById("paymentform");

    let formData = new FormData();
    formData.append('productname', paymentform.elements["productname"]);
    formData.append('amount', paymentform.elements["amount"]);

    fetch("/pay.php", {
        method: "POST",
        body: formData
    })
    .then(function (response) {
        return response.json();
    })
    .then(function (session) {
        return stripe.redirectToCheckout({ sessionId: session.id });
    })
    .then(function (result) {
        // If redirectToCheckout fails due to a browser or network
        // error, you should display the localized error message to your
        // customer using error.message.
        if (result.error) {
        alert(result.error.message);
        }
    })
    .catch(function (error) {
        console.error("Error:", error);
    });
</script>
<?php } else{
header("location:http://www.example.com");
}?>


在JavaScript代码中,在事件侦听器之前添加了一个
.submit()
。这会导致重定向页面而不提交信息。请检查以下代码

<html>
<head>
    <script src="https://polyfill.io/v3/polyfill.min.js?version=3.52.1&features=fetch"></script>
    <script src="https://js.stripe.com/v3/"></script>
</head>
<?php if(isset($_POST['productname']) && $_POST['productname']!="" && isset($_POST['amount']) && $_POST['amount']!="")
{ ?>
    <form name="paymentform" class="paymentform" style="display:none" id="paymentform" method="post" action="pay.php">
        <input name="productname" type="hidden" value="<?=$_POST['productname'];?>">
        <input name="amount" type="hidden" value="<?=$_POST['amount'];?>">
    </form>
    <script type="text/javascript">
    // Create an instance of the Stripe object with your publishable API key
    var stripe = Stripe("pk_test_576576576576576");
    var paymentform = document.getElementById("paymentform");

    let formData = new FormData();
    formData.append('productname', paymentform.elements["productname"]);
    formData.append('amount', paymentform.elements["amount"]);

    fetch("/pay.php", {
        method: "POST",
        body: formData
    })
    .then(function (response) {
        return response.json();
    })
    .then(function (session) {
        return stripe.redirectToCheckout({ sessionId: session.id });
    })
    .then(function (result) {
        // If redirectToCheckout fails due to a browser or network
        // error, you should display the localized error message to your
        // customer using error.message.
        if (result.error) {
        alert(result.error.message);
        }
    })
    .catch(function (error) {
        console.error("Error:", error);
    });
</script>
<?php } else{
header("location:http://www.example.com");
}?>


我也试过了,但仍然没有重定向到签出页面:(。你的chrome开发者控制台中有任何错误吗?仍然相同,它没有重定向到签出页面检查ss收到了此错误。我也试过了,仍然没有重定向到签出页面:(.你的chrome开发者控制台中有错误吗?还是一样,它没有重定向到签出页面检查ss得到这个错误。