最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何从js前端的节点后端访问值

运维笔记admin9浏览0评论

如何从js前端的节点后端访问值

如何从js前端的节点后端访问值

我想从我的节点后端访问js文件中的值。

这里是节点代码...节点:

(async () => {
    const session = await stripe.checkout.sessions.create({
        payment_method_types: ['card'],
        line_items: [{
            name: 'T-shirt',
            description: 'Comfortable cotton t-shirt',
            images: ['.png'],
            amount: 500,
            currency: 'eur',
            quantity: ((req.body.tickets - 0) + (req.body.tickets_kid - 0)),
        }],
        success_url: 'http://localhost:3000/thank-you?session_id={session.id}',
        cancel_url: 'https://localhost:3000/tickets',
});

res.send(session);
})();

...和js代码

const stripe = Stripe('secretkey');

const session = ?
console.log(session);

async function stripeCheckout() {
    console.log('activated checkout')

    const { error } = await stripe.redirectToCheckout({
        // Make the id field from the Checkout Session creation API response
        // available to this file, so you can provide it as parameter here
        // instead of the {{CHECKOUT_SESSION_ID}} placeholder.
        sessionId: '{{session.id}}'
    })
    window.alert(error.message);
    // If `redirectToCheckout` fails due to a browser or network
    // error, display the localized error message to your customer
    // using `error.message`.
};

现在,我正在尝试将会话ID放入js文件。感谢您的帮助。

回答如下:

您需要向后端发出一些请求才能获得响应。

发布评论

评论列表(0)

  1. 暂无评论