我有一些AJAX代码可以获取“删除”按钮并将其发送到rem_cart.php
$(document).on('click', '.delete', function(){
var product_id = $(this).attr('id');
var action = "Delete";
console.log(product_id);
if (confirm("Are you sure you want to remove
this product from your cart?")) {
$.ajax({
url: "../PHP_Scripts/rem_cart.php",
method: "POST",
dataType: "json",
data: {
product_id: product_id,
action: action
},
success:function(data){
$('#order_table').html(data.order_table);
$('.badge').text(data.cart_item);
}
});
}else{
return false;
}
});
这里是rem_cart.php
:
if (isset($_POST['action'] == "Delete")) {
foreach ($_SESSION['shopping_cart'] as $key => $value) {
if ($value['product_id'] == $_POST['product_id']) {
unset($_SESSION['shoppingcart'][$key]);
}
}
}
会话密钥未设置。
“网络”标签也显示所有正确的信息:
product_id: 12
action: Delete
有人可以照亮吗?