0
目前,当点击“添加到购物车”按钮时,以下JavaScript会更新购物车的值click
。更新页面加载
我试图在页面加载或刷新时在pageload
上更新值。
目前的价值只在click
更新:
<script type="text/javascript"><!--
$('#button-cart').on('click', function() {
$.ajax({
url: 'index.php?route=checkout/cart/add',
type: 'post',
data: $('#product input[type=\'text\'], #product input[type=\'hidden\'], #product input[type=\'radio\']:checked, #product input[type=\'checkbox\']:checked, #product select, #product textarea'),
dataType: 'json',
beforeSend: function() {
$('#button-cart').button('loading');
},
complete: function() {
$('#button-cart').button('reset');
},
success: function(json) {
$('.alert, .text-danger').remove();
$('.form-group').removeClass('has-error');
if (json['success']) {
$('.breadcrumb').after('<div class="alert alert-success">' + json['success'] + '<button type="button" class="close" data-dismiss="alert">×</button></div>');
$('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');
$('html, body').animate({ scrollTop: 0 }, 'slow');
$('#cart > ul').load('index.php?route=common/cart/info ul li');
}
},
});
});
//--></script>
我已经尝试了很多东西,有没有运气我曾尝试使用这个(这什么都不做)加载的值:
function readyFn(jQuery) {
$('#cart > button').load(function() {
$('.breadcrumb').after('<div class="alert alert-success">' + json['success'] + '<button type="button" class="close" data-dismiss="alert">×</button></div>');
$('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');
$('html, body').animate({ scrollTop: 0 }, 'slow');
$('#cart > ul').load('index.php?route=common/cart/info ul li');
});
$(document).ready(readyFn);
// or:
$(window).on("load", readyFn);
}
只是想知道如果有人能帮助我如何在它click
更新相同的方式刷新/页load
上加载。
在此先感谢。
感谢您的帮助,我会注意到未来。没有解决我的问题,但有用的信息谢谢! – Beth