使用此代码来提取具有特定类的表单并处理某些操作:
$('.stripe_payment').submit(function(e) {
var frm = $(this);
var token_input = $('#' + frm.attr('token_input'));
console.log("submit");
console.log( $(token_input).val() );
if($(token_input).val() == "") {
console.log("empty tk");
var handler = StripeCheckout.configure({
key: 'pk_test_kOFWqH1EnP8UcrS3AqCYd4mQ',
image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
locale: 'auto',
token: function(token) {
if(token.id) {
$(token_input).val(token.id);
$(frm).submit();
return true;
}
}
});
// Open Checkout with further options:
handler.open({
name: 'Integra Telecommunications Ltd',
description: '2 widgets',
zipCode: true,
currency: 'gbp',
amount: 2000
});
e.preventDefault();
}
// Close Checkout on page navigation:
window.addEventListener('popstate', function() {
handler.close();
});
});
和我的HTML表单:
<form id="topup_form" class="stripe_payment" token_input="stripe_token" method="post" action="/telecoms/sms/balance?ac=<?php echo $account["sequence"]; ?>">
<input type="text" id="stripe_token" />
<input type="submit" name="submit" id="topup_submit" class="btn btn-default pull-right" value="Order Credits" />
</form>
提交表单时,处理程序会打开并输入详细信息。
然后返回 token.id
并将其填充在表单的输入字段中,但是$(frm).submit();
则不能正常提交表单。
我尝试将$(frm).submit();
更改为$(this).submit();
,也尝试将return true;
更改为return false;
,但仍然相同