布伦特里插入式UI - 使用AJAX发送形式 [英] Braintree Drop-in UI - send form using AJAX

查看:177
本文介绍了布伦特里插入式UI - 使用AJAX发送形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现布伦特里插入式UI和我想用一个自定义的jQuery的AJAX方法发送的形式。 previously,我以前使用jQuery的序列化()方法来发送(非插入式UI)的形式,但对于新的(动态加载)DROPIN UI形成序列化()方法似乎并不奏效(所述payment_method_nonce值设置为空)。 然而,通过一个基本的HTML表单发送的形式(不阿贾克斯)似乎是工作的罚款,所以我payment_method_nonce是存在的,它只是相处的方式丢失了。

I'm trying to implement the Braintree Drop-in UI and I want to send the form using a custom jQuery ajax method. Previously, I used to send the (non drop-in UI) form using the jQuery serialize() method, but for the new (dynamically loaded) Dropin UI form the serialize() method doesn't seem to be working (the payment_method_nonce value is set to empty). However, sending the form through a basic html form (without ajax) seems to be working fine, so my payment_method_nonce is there, its just getting lost along the way.

我如何才能确保序列化()方法不输payment_method_nonce值?

How can I make sure that the serialize() method doesn't lose the payment_method_nonce value?

或作为一个更普遍的问题,我怎么能发送插入式用户界面的形式用ajax?

Or as a more general question, how can I send the Drop-in UI form using ajax?

我知道,有一个paymentMethodNonceReceived标志使用做braintree.setup的时候,但是,这并不在我的情况下工作,我需要保持code发送的请求/处理从布伦特里分离的响应。设置。

I know that there's a paymentMethodNonceReceived flag to use when doing the braintree.setup, but that doesn't work in my case as I need to keep the code for sending request / handling the response separated from the braintree.setup.

干杯

推荐答案

显然,paymentMethodNonceReceived方法是要走的路到底。 一旦令牌创建我用它来创建隐藏字段,它是的形式,其然后可以使用序列化()方法,没有任何问题序列的一部分。这里有一个code样品:<​​/ P>

Apparently the paymentMethodNonceReceived method was the way to go in the end. Once the token is created I use it to create a hidden field which is part of the form, which can then be serialised using the serialize() method without any problem. Here's a code sample:

<script type="text/javascript">
    braintree.setup("PaymentTokenGoesHere", "dropin", {
        container: "myDiv",
        paymentMethodNonceReceived: function (event, nonce) {
            $('#myForm').append("<input type='hidden' name='payment_method_nonce' value='" + nonce + "'></input>");
            CallAjaxMethod();
        }
    });
</script>

这篇关于布伦特里插入式UI - 使用AJAX发送形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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