gpt4 book ai didi

javascript - Uncaught ReferenceError : Stripe is not defined - STRIPE ERROR

转载 作者:行者123 更新时间:2023-11-28 03:07:56 24 4
gpt4 key购买 nike

我正在尝试将 Stripe 元素实现到我的 Rails 应用程序中,但我似乎无法正确包含 stripe.js。这是我的 application.html

<%= tag :meta, name: "stripe-key", content: Figaro.env.stripe_publishable_key %>
<script type="text/javascript" src="https://js.stripe.com/v3/"</script>
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>

JS

var stripe = Stripe($("meta[name='stripe-key']").attr("content"))
var elements = stripe.elements();

var card = elements.create('card', {
style: {
base: {
iconColor: '#999',
color: '#505652',
lineHeight: '40px',
fontWeight: 300,
fontFamily: 'Helvetica Neue',

'::placeholder': {
color: '#CFD7E0',
},
},
}
});
// Add an instance of the card UI component into the `card-element` <div>
card.mount('#card-element');

表格

<form action="/charge" method="post" id="payment-form">
<div class="form-row">
<label for="card-element">
Credit or debit card
</label>
<div id="card-element">
</div>
<div id="card-errors"></div>
</div>

<button>Submit Payment</button>
</form>

每次加载页面时,我都会在控制台中收到此错误Uncaught ReferenceError: Stripe is not Defined - STRIPE ERROR。我认为这与我加载 stripe.js 的方式有关,但我不确定?

最佳答案

我怀疑发生的情况是 Stripe.js 在您自己的 javascript 之后加载。尝试将 Stripe.js 移至 header 中您自己的 javascript 之上。

关于javascript - Uncaught ReferenceError : Stripe is not defined - STRIPE ERROR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60438761/

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