[英]Pop up djstripe payments modal without button click
Since I only have one djstripe subscription plan, I'm trying to get my djstripe payments/subscribe page to pop up the payments modal without a click. 由于我只有一个djstripe订阅计划,因此我试图使我的djstripe付款/订阅页面无需点击即可弹出付款方式。 The JavaScript that works with the click of a button is this: 单击按钮即可使用的JavaScript是这样的:
$(function() {
$('body').on("click", '.djstripe-subscribe button[type=submit]', function(e) {
e.preventDefault();
// retrieve current $(".djstripe-subscribe")
var $form = $(e.target).parents('form'),
token = function(res) {
$form.find("input[name=stripe_token]").val(res.id);
$("button[type=submit]").attr("disabled", "true");
$('#in-progress').modal({"keyboard": false})
$('.progress-bar').animate({width:'+=100%'}, 2000);
$form.trigger("submit");
};
StripeCheckout.open({
key: "{{ STRIPE_PUBLIC_KEY }}",
name: 'Payment Method',
panelLabel: 'Add Payment Method',
token: token
});
return false;
});
{% if PLAN_LIST|length > 1 %}
$('.djstripe-change-plan').click(function(e){
$("button[type=submit]").attr("disabled", "true");
$('#in-progress').modal({"keyboard": false})
$('.progress-bar').animate({width:'+=100%'}, 2000);
var $form = $(this);
$form.trigger("submit");
});
{% endif %}
});
I've been able to get the modal to pop up by removing the wrapper function and putting the script in a document ready function, like this: 通过删除包装器函数并将脚本放入文档就绪函数中,我已经能够弹出模态,如下所示:
$(document).ready(function(e) {
// retrieve current $(".djstripe-subscribe")
var $form = $(e.target).parents('form'),
token = function(res) {
$form.find("input[name=stripe_token]").val(res.id);
$("button[type=submit]").attr("disabled", "true");
$('#in-progress').modal({"keyboard": false})
$('.progress-bar').animate({width:'+=100%'}, 2000);
$form.trigger("submit");
};
StripeCheckout.open({
key: "{{ STRIPE_PUBLIC_KEY }}",
name: 'Payment Method',
panelLabel: 'Add Payment Method',
token: token
});
return false;
});
{% if PLAN_LIST|length > 1 %}
$('.djstripe-change-plan').click(function(e){
$("button[type=submit]").attr("disabled", "true");
$('#in-progress').modal({"keyboard": false})
$('.progress-bar').animate({width:'+=100%'}, 2000);
var $form = $(this);
$form.trigger("submit");
});
{% endif %}
However, this eliminates the .djstripe-subscribe button[type=submit] selector, causes errors with e.preventDefault() unless I remove it as shown in this code snippet, and makes the "server update" that comes up after a payment method is submitted crank eternally with no results. 但是,这消除了.djstripe-subscribe button [type = submit]选择器,导致e.preventDefault()导致错误,除非我如此代码片段所示将其删除,并在付款方式后显示“服务器更新”永久提交曲柄,没有结果。 How can I get the modal to pop up and update successfully? 我怎样才能使模式弹出并成功更新?
您可以执行此操作的一种方法是在第一版代码上使用jQuery的.click()方法( https://api.jquery.com/click/ ),但是在页面加载时“单击”该元素吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.