【问题标题】:object is not a function on stripe javascript [duplicate]对象不是条带javascript上的函数[重复]
【发布时间】: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


    【解决方案1】:

    将提交按钮的 ID/名称更改为其他名称..aka name="btnSubmit"

    【讨论】:

    • 嗯...做到了....但是为什么呢?
    • 因为您使用名称 document.formName.elementNamedocument.formName.methodName 覆盖了提交方法。那么当你有一个值相同的方法和元素名时,浏览器应该怎么做呢?
    猜你喜欢
    • 2018-05-09
    • 1970-01-01
    • 2016-08-06
    • 2015-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-17
    相关资源
    最近更新 更多