我是新来的方形支付表单集成。 我正在根据https://docs.connect.squareup.com/articles/adding-payment-form.when上的文档整合表单,当我将表单嵌入到单个页面时,它工作正常,但是当我加载表单时脚本在ajax中显示错误“ReferenceError:SqPaymentForm未定义”。 有人请告诉我一种将表单嵌入ajax的方法。
I am new to square payment form integration. i am integrating the form according to the documentation on https://docs.connect.squareup.com/articles/adding-payment-form .when i am embedding the form on a individual page it works fine but when i am loading the form scripts in ajax it showing the error " ReferenceError: SqPaymentForm is not defined ". some one please suggest me a way to embed the form in ajax.
最满意答案
这里的问题是,你可能试图在页面上运行JavaScript(它有类似var paymentForm = new SqPaymentForm({...在外部库加载之前。
如果您异步加载https://js.squareup.com/v2/paymentform ,则需要延迟页面上JavaScript的执行,直到外部库加载完成。 你可以通过onload事件来做到这一点,或等待页面完全加载(或许多其他方式,搜索“在异步之后延迟javascript”),但最简单的方法是同步加载库。
The problem here is that you are likely trying to run the javascript on the page (that has something like var paymentForm = new SqPaymentForm({... before the external library has loaded.
If you are loading the https://js.squareup.com/v2/paymentform asynchronously, you'll need to delay the execution of the javascript on the page until after the external library has loaded. You can do this via onload events, or waiting until the page is fully loaded (or lots of other ways, search for "delaying javascript after async", but the easiest way would be to just load the library synchronously.
更多推荐
发布评论