I'm trying to remove a product from cart using php. I'm able to delete the product using input and button type submit like this.
<input type="checkbox" name="remove_code[]" value="<?php echo htmlentities($row['id']);?>" />
<button id="remove-from-cart" type="submit">delete</button>
I have to select each checkbox and click submit to remove product everytime. Now I want to remove item from cart using ajax without refreshing the whole page and I want to use only button or img tag instead of input tag. This is my php code and
// Code for Remove a Product from Cart
if(isset($_POST['remove_code']))
{
if(!empty($_SESSION['cart'])){
foreach($_POST['remove_code'] as $key){
unset($_SESSION['cart'][$key]);
}
// echo "<script>alert('Your Cart has been Updated');</script>";
}
}
this is my ajax request
$(document).on("click", "#remove-from-cart", function () {
$.ajax({
url: "my-cart.php",
type: "post",
success: function () {
},
});
});