简体   繁体   中英

Uncaught ReferenceError: Stripe is not defined MVC

I have simple payment page which I am going to show in popup using partial view. In .cshtml page, I have following javascript code below html code:

<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script type="text/javascript">
    $('document').ready(function () {
        Stripe.setPublishableKey(publishablekey);
    });
</script>

When I run the project that popup shows successfully but in the console, there is an error: Uncaught ReferenceError: Stripe is not defined

This happens when the browser cannot load the Stripe js library. That could happen because your user has lost their internet connection, or maybe (but less likely) the website that is serving the Stripe library is temporarily unavailable. To handle this case gracefully you could check to see whether Stripe is undefined.

For example:

if (typeof Stripe === "undefined") {
    alert("Unexpected Error");
}

Or check for the opposite before using it

if (typeof Stripe !== "undefined") {
    Stripe.setPublishableKey(publishablekey);
}

我刚刚在该页面中添加了Stripe参考行: <script type="text/javascript" src="https://js.stripe.com/v2/"></script>弹出窗口。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM