[英]How to remove product from cart
我对javascript有疑问。 我有一个购物车和一个从购物车中删除产品的功能。 购物车为空时,如何重定向到主页?
这是我的功能删除产品。
function removeCart(key) {
$.ajax({
url: 'index.php?route=checkout/cart/update',
type: 'post',
data: 'remove=' + key,
dataType: 'json',
success: function(json) {
$('.success, .warning, .attention, .information').remove();
if (json['output']) {
$('#cart_total').html(json['total']);
$("table.total tr:last td:last").text(json['total'].split('-')[1]);
$('#cart .content').html(json['output']);
}
}
});
}
执行更新时,您应该得到购物车。 如果购物车是空的,您可以在ajax响应中将其返回。 例如,通过在数组中设置一个emptyCart键:
function removeCart(key) {
$.ajax({
url: 'index.php?route=checkout/cart/update',
type: 'post',
data: 'remove=' + key,
dataType: 'json',
success: function(json) {
$('.success, .warning, .attention, .information').remove();
if (json['emptyCart']) {
location.href="/where-you-want-it-to-go";
}
if (json['output']) {
$('#cart_total').html(json['total']);
$("table.total tr:last td:last").text(json['total'].split('-')[1]);
$('#cart .content').html(json['output']);
}
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.