未捕获的ReferenceError:未定义条纹-STRIPE ERROR [英] Uncaught ReferenceError: Stripe is not defined - STRIPE ERROR

查看:42
本文介绍了未捕获的ReferenceError:未定义条纹-STRIPE ERROR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to implement Stripe elements into my rails app, but I can't seem to include the stripe.js correctly. Here is my 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>

每次加载页面时,都会在控制台中出现此错误.未捕获的ReferenceError:未定义条纹-STRIPE ERROR .我认为这与我加载stripe.js的方式有关,但是我不确定吗?

Every time I load the page I get this error in the console Uncaught ReferenceError: Stripe is not defined - STRIPE ERROR. I think it has something the to do with the way I'm loading stripe.js but I'm not sure?

推荐答案

我怀疑正在发生的事情是Stripe.js在您自己的JavaScript之后加载了.尝试将Stripe.js移到标题中您自己的javascript上方.

I suspect what's happening is that Stripe.js is loading AFTER your own javascript. Try moving Stripe.js above your own javascript in the header.

这篇关于未捕获的ReferenceError:未定义条纹-STRIPE ERROR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆