javascript – 更新条带数据量
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 更新条带数据量,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2077字,纯文字阅读大概需要3分钟。
内容图文
![javascript – 更新条带数据量](/upload/InfoBanner/zyjiaocheng/707/9c9b86f86834409fbaea7fbcfb354f41.jpg)
我正在将Stripe实施到一个django网站,除了一部分外,一切正常.在我的购物车中,用户可以更新更改总数的项目.除了在Stripe Checkout js脚本上设置数据量之外,一切正常.
当页面加载时,一切都很好,但是如果客户更改了他们的购物车,则数据量不会更新.我有另一个显示总数的框,这个数量更新很好.
<!-- here is the script tag in HTML-->
<script
id="stripe-script"
src="https://checkout.stripe.com/checkout.js"
class="stripe-button"
data-image="{% static 'img/marketplace.png' %}"
data-key="{{ STRIPE_PUBLIC_KEY }}"
data-name="Serendipity Artisan Blends"
data-description="Purchase Items"
data-amount="{{ cart_stripe_total }}">
</script>
然后我尝试更新的javascript是这样的:
function updateTotal(amount) {
/* update the total in the cart in both the table cell and
in the stripe button data-amount */
var totalStr = shoppingTotalCell.text().replace('$', ''),
originalTotal = parseFloat(totalStr),
newTotal = originalTotal + amount,
newTotalStripe = newTotal * 100,
newTotalStr = newTotal.toFixed(2),
script = $('#stripe-script');
shoppingTotalCell.text('$' + newTotalStr);
console.log(script.data("amount"));
// this returns the correct original amount
script.data("amount", newTotalStripe);
console.log(script.data("amount"));
/* this returns the updated amount, however the HTML data-amount
attribute does not update. */
}
解决方法:
事实证明,要获得条带付款的动态数据量,您必须使用Custom Checkout而不是简单结帐.这段代码就行了.
<button class="btn btn-primary btn-lg" id="stripe-button">
Checkout <span class="glyphicon glyphicon-shopping-cart"></span>
</button>
<script>
$('#stripe-button').click(function(){
var token = function(res){
var $id = $('<input type=hidden name=stripeToken />').val(res.id);
var $email = $('<input type=hidden name=stripeEmail />').val(res.email);
$('form').append($id).append($email).submit();
};
var amount = $("#stripeAmount").val();
StripeCheckout.open({
key: '{{ STRIPE_PUBLIC_KEY }}',
amount: amount,
name: 'Serendipity Artisan Blends',
image: '{% static "img/marketplace.png" %}',
description: 'Purchase Products',
panelLabel: 'Checkout',
token: token
});
return false;
});
</script>
内容总结
以上是互联网集市为您收集整理的javascript – 更新条带数据量全部内容,希望文章能够帮你解决javascript – 更新条带数据量所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。