Skip to content Skip to sidebar Skip to footer

Using In_array To Compare Array Data Doesn't Work

As you can see in the picture, several products. Each product div has a remove button. When I hit this button, the product name of that specific product is stored into a toBeRemove

Solution 1:

There's also a bug in your Js code.

Replace your Js code with this instead and try again.

let removeBtn = document.querySelectorAll('.btn-remove');
removeBtn = [...removeBtn];

removeBtn.forEach((item) => {
    item.addEventListener('click', function() {
        const toBeRemovedName = item.parentNode.parentNode.children[0].innerHTML;

        $.ajax({
            url: "./shopping_cart.php?toBeRemovedName=" + toBeRemovedName,
            method: "GET"
        });
    });
});

Why not hide the element with JavaScript instead after an HTTP status code of 200. Furthermore, If the element has been removed as you mentioned in one of your comments, hiding it with JavaScript will be a better option and you get a good user experience too. Nobody really likes page reload these days. If you want a reload, you can do that with javascript using the code below.

 window.location.reload()

That'd give you a window reload as well.


Post a Comment for "Using In_array To Compare Array Data Doesn't Work"