我使用的是 Stripe 文档中的代码示例,位于此处。但是,当这个被处理时,$form.get(0).submit();我得到了这个错误。
Uncaught TypeError: Property 'submit' of object #<HTMLFormElement>
is not a function
我的代码如下:
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('button').prop('disabled', false);
  } else {
    // token contains id, last4, and card type
    var token = response.id;
    console.log(token);
    // Insert the token into the form so it gets submitted to the server
    $form.append($('<input type="hidden" name="stripeToken" />').val(token));
    // and re-submit
    $form.get(0).submit();    **//Error happens here**
  }
};
jQuery(function($) {
  $('#payment-form').submit(function(e) {
    var $form = $(this);
    // Disable the submit button to prevent repeated clicks
    $form.find('#payment-button').prop('disabled', true);
    Stripe.createToken($form, stripeResponseHandler);
    // Prevent the form from submitting with the default action
    return false;
  });
});
我究竟做错了什么?