【发布时间】:2014-07-19 13:08:04
【问题描述】:
好的,所以我按照条纹教程创建了自定义表单。我的javascript代码如下。现在我的信用卡字段是更大表单的一部分,而不仅仅是这些字段。它的 ID 是 payment-form,就像您认为它在下面的代码中一样。
我的问题是,当代码运行时,一切正常,直到这一行:$form.get(0).submit(); 我收到此错误:Uncaught TypeError: object is not a function 我尝试删除一些东西并使其:$form.submit 但这导致了无限循环。
那么我需要做些什么来解决这个问题呢?是什么导致了这个问题?
我的代码:
<script type="text/javascript">
Stripe.setPublishableKey('<?php echo $key; ?>');
var stripeResponseHandler = function(status, response) {
var $form = $('#payment-form');
if (response.error) {
// Show the errors on the form
$form.find('.payment-errors').text(response.error.message);
$form.find('#submit').prop('disabled', false);
} else {
// token contains id, last4, and card type
var token = response.id;
// Insert the token into the form so it gets submitted to the server
$form.append($('<input type="text" name="stripeToken" />').val(token));
$form.find('[data-stripe]').val('');
// and re-submit
$form.get(0).submit();
}
};
jQuery(function($) {
$('#payment-form').submit(function(event) {
var $form = $(this);
// Disable the submit button to prevent repeated clicks
$form.find('#submit').prop('disabled', true);
Stripe.card.createToken($form, stripeResponseHandler);
// Prevent the form from submitting with the default action
return false;
});
});
</script>
【问题讨论】:
标签: javascript jquery stripe-payments