lundi 4 novembre 2019

How to delete a product with ajax

I want to delete this product instantly when I click the delete button, so far when I click the delete button it hides the icon and the product is still showing until I refresh the page then the product is gone, how can I fix this?

Script

   function deleteFromFavourites(productid, userid) {
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    $.ajax({
        method: 'post',
        url: `product/${productid}/unlike`,
        data: {
            'user_id': userid,
            'product_id': productid,
        },
        success: function () {

    console.log($('#deletefavourite' + productid));
            // show delete button
            $('#deletefavourite' + productid).hide();
        },
    });
    }

Blade file

   <a style="display: " id="deletefavourite" onClick="deleteFromFavourites(, )">Delete</a>


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire