使用Stripes支付流程示例时出错
Getting an error when using Stripes payment process example
我使用的是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;
});
});
我做错了什么?
在收到错误的行上,请尝试以下操作:
jQuery($form.get(0)).submit();
您的问题是,您得到了第一个HTML元素,但为了对此调用"submit",您需要用jQuery包装它。
相关文章:
- javascript中的数组出错
- 节点Js:How to catch a“;没有这样的文件或目录“;读取线模块出错
- PHP AJAX图片上传示例不上传
- API密钥使用和检查示例
- 三星智能电视应用程序;Brightcove示例应用程序远程控制问题
- 在Meteor项目中安装并包含npm模块后出错
- 解析JSON并从中删除对象会出错
- AngularJS指令出错-无法读取属性'编译'的未定义
- 骨干模型默认值-todos.js示例中不必要的代码
- d3js文本传输-示例代码不起作用
- 使用javascript在MVC中查找网格长度时出错
- 尝试调用AngularJS上的函数时出错
- Eloquent JavaScript递归示例如何终止为返回1,但仍然输出指数值
- JQuery示例不起作用-“;对象没有't支持属性或方法'按钮'&”;
- $locationProvider html5mode导致“;无法获取“;刷新时出错-AngularJS Node应用程
- 脸书示例登录应用程序中出错
- 使用Stripes支付流程示例时出错
- 谷歌云存储-尝试javascript示例时出错
- 执行套接字时出错.IO聊天示例node.js
- 使用示例服务在控制器之间传递数据时出错