zun*_*ndi 5 javascript jquery stripe-payments
我正在使用Stripe Checkout,桌面上的弹出窗口一切正常.当我在移动设备上查看该网站时(特别是在香草Android 4.3上的Chrome,也尝试使用类似结果的Opera for Android),一个弹出窗口似乎打开了一小段时间但随后关闭.我从来没有看到它,它也不在另一个打开的标签中.
我已阅读此文档,我的代码符合要求.
这是我正在使用的JavaScript:
$(document).ready(function() {
//The actual giving part
$('a.payamount').click(function(e) {
window.amountToGive = $(this).data('amount');
// Open Stripe Checkout with further options
stripeHandler.open({
name: campaignName,
description: 'Give $' + (window.amountToGive / 100) + ' to ' + campaignName,
amount: window.amountToGive
});
});
var stripeHandler = StripeCheckout.configure({
key: 'mykeygoeshere',
image: '/img/g.png',
locale: 'auto',
token: function(token) {
//Add campaign info
token['campaign_id'] = campaignId;
token['amount'] = window.amountToGive;
postStripeData(token);
}
});
// Close Checkout on page navigation
$(window).on('popstate', function() {
stripeHandler.close();
});
});
function postStripeData(token) {
showLoadingModal();
$.ajax({
method: 'POST',
url: postStripeDataUrl,
data: token
})
.always(function(data_jqXHR, textStatus, jqXHR_errorThrown) {
if (textStatus.indexOf('error') == -1) {
//POST'ed ok
console.log(data_jqXHR);
window.location.href = data_jqXHR;
} else {
alert('Error while posting!');
}
});
}
Run Code Online (Sandbox Code Playgroud)
我正在使用https://checkout.stripe.com/checkout.js.
我已尝试通过Chrome开发者工具对其进行调试,您可以在其中查看Android日志,并且不会显示任何错误.
经过一段时间的调试,似乎缺少的是e.preventDefault();click 函数中的 a :
$('a.payamount').click(function(e) {
e.preventDefault();
//... rest of code
Run Code Online (Sandbox Code Playgroud)