当点击 opencart 中标题下拉购物车上的删除按钮时,我尝试刷新页面并删除购物车删除数据。我在 cart.tpl 上找到了位置,但是当我点击那个按钮时我找不到功能的位置。
onclick="cart.remove('<?php echo $product['key']; ?>');
然后我尝试使用 jquery 刷新页面
<script type="text/javascript">
jQuery(document).ready(function(){
$('.dropdown-menu .text-center .btn-xs').click(function(){
location.reload();
});
});
</script>
它刷新页面但不删除购物车产品。
最佳答案
打开文件 catalog/view/javascript/common.js
。转到 第 200 行
。
改变这个
'remove': function(key) {
$.ajax({
url: 'index.php?route=checkout/cart/remove',
type: 'post',
data: 'key=' + key,
dataType: 'json',
beforeSend: function() {
$('#cart > button').button('loading');
},
complete: function() {
$('#cart > button').button('reset');
},
success: function(json) {
// Need to set timeout otherwise it wont update the total
setTimeout(function () {
$('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');
}, 100);
if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
location = 'index.php?route=checkout/cart';
} else {
$('#cart > ul').load('index.php?route=common/cart/info ul li');
}
}
为此
'remove': function(key) {
$.ajax({
url: 'index.php?route=checkout/cart/remove',
type: 'post',
data: 'key=' + key,
dataType: 'json',
beforeSend: function() {
$('#cart > button').button('loading');
},
complete: function() {
$('#cart > button').button('reset');
},
success: function(json) {
// Need to set timeout otherwise it wont update the total
setTimeout(function () {
$('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');
}, 100);
if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
location = 'index.php?route=checkout/cart';
} else {
$('#cart > ul').load('index.php?route=common/cart/info ul li');
}
location.reload();
}
关于javascript - 如何刷新页面并删除删除产品,当单击 opencart 标题下拉购物车中的删除按钮时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37561455/