我希望当我重新提交表单时,它会转到下一页。
但是,
当我试图重新提交表单时,它递归调用
'$('#payment-form').submit(function(e){}'
函数和程序进入无限循环。
我也试试,
$form.get(0).submit();
我不知道这段代码究竟是做什么的,但它不起作用。
我可以做哪些更改,以便代码正常运行。请建议我找出解决方案。
代码:
<script type="text/javascript">
// This identifies your website in the createToken call below
Stripe.setPublishableKey('pk_test_JvzbQnE7YDpeiZOMQO0D9Mar');
var stripeResponseHandler = function( status , response) {
var $form = $('#payment-form');
if (response.error) {
// Show the errors on the form
alert("error...!");
var error = " error : "+response.error.message;
$form.find('.payment-errors').text(error);
$form.find('button').prop('disabled', false);
return false;
}
else
{
alert(" Card Submited..");
var token = response.id;
$form.find('.payment-errors').text('Your Card is Submited..! :: ' + token);
document.getElementById("stripeToken").value = token;
// and re-submit
$form.submit();
}
};
jQuery(function($) {
$('#payment-form').submit(function(e){
//function submitCard() {
var $form = $('#payment-form');
var number = $('.card-number').val();
var cvc = $('.card-cvc').val();
var exp_month = $('.card-expiry-month').val();
var exp_year = $('.card-expiry-year').val();
//var email =$('.card-email').val();
//var amount =$('.card-amount').val();
if (!Stripe.validateCardNumber(number)) {
alert('The credit card number appears to be invalid.');
return false;
}
// Validate the CVC:
if (!Stripe.validateCVC(cvc)) {
alert('The CVC number appears to be invalid.');
return false;
}
// Validate the expiration:
if (!Stripe.validateExpiry(exp_month, exp_year)) {
alert('The expiration date appears to be invalid.');
return false;
}
// Disable the submit button to prevent repeated clicks
$form.find('#submit').prop('disabled', true);
Stripe.card.createToken({
number: $('.card-number').val(),
cvc: $('.card-cvc').val(),
exp_month: $('.card-expiry-month').val(),
exp_year: $('.card-expiry-year').val()
}, stripeResponseHandler);
//Stripe.card.createToken($form, stripeResponseHandler);
// Prevent the form from submitting with the default action
return false;
});
});
</script>