我正在尝试单独删除购物车中添加的产品以及点击时整个购物车。我有两个方案如果用户已登录或未登录。在这两种情况下,当我删除单行时,它会被删除,但是当我重新加载页面时,该行又会出现。 数据完全从数据库中删除,但在前端它无法正常工作,但在删除整个购物车的情况下工作正常。 jQuery 或 PHP 中的问题在哪里?我的购物车视图是:
以下是 Jquery
中删除功能的代码 $(document).on('click' , '.delBtn' , function(){
var rowId = $(this).attr('rel');
alert(rowId)
var thisElement = $(this);
swal({
title: "Are you sure?",
text: "You want to delete the domain from your cart!",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonText: "Yes, delete it!",
cancelButtonClass: "btn-warning",
cancelButtonText: "No, cancel plx!",
closeOnConfirm: false
},
function(isConfirm) {
if(isConfirm) {
alert("yes");
$.ajax({
type : 'POST',
url : base_url+'home/remove',
data : {id:rowId},
beforeSend : function(){
},
success : function(data){
alert(data)
if(data == 'true'){
swal({
type : 'success',
title : "Done!",
text : "Domain Deleted From your Cart!",
timer: 2000,
showConfirmButton: false
});
var total_item = $('.total_items').html();
$('.total_items').html(parseInt(total_item)-1);
thisElement.closest('tr').remove();
var sum_value = update();
if(sum_value == 0) {
$('.view_cart_table').remove();
$('h2.empty').html('Your Cart is empty.');
}else{
$('.total_amount span').html(sum_value);
}
}
if(data == 'all'){
swal({
type : 'success',
title : "Done!",
text : "Your Cart is Empty Now!",
timer: 2000,
showConfirmButton: false
});
var total_item = $('.total_items').html();
$('.total_items').html(total_item-total_item);
$('.view_cart_table').remove();
$('h2.empty').html('Your Cart is empty.');
}
}
});
}
});
});
在数据中它的返回数据值,但是当我重新加载我的页面时它再次出现
这是 Php Code点火器代码
public function remove(){ /* This Function is for Removing domains From cart Whole and individually */
$rowid = $this->input->post('id');
if($this->session->userdata('users_Data')){
$user_id = $this->session->userdata['users_Data']['user_id'];
}else{
$user_id = '';
}
if($rowid === ''.$user_id.'all'){
$this->main_model->del_all_cart($user_id);
$this->cart->destroy();
echo "all";
}else if($rowid === 'all'){
$this->cart->destroy();
echo "all";
}else{
if($user_id == ''){
$data = array(
'id' => $rowid,
'qty' => 0
);
$this->cart->update($data);
echo "true";
}else{
$this->main_model->del_single_cart($rowid);
$data = array(
'id' => $rowid,
'qty' => 0
);
$this->cart->update($data);
echo "true";
}
}
}
任何人都可以帮忙??????