0

In Magento 2 I want to Override Default Action on Add to WishList

I have tried e.preventDefaults() but i think it only override Href Actions

Here is My Code

require(['jquery', 'mage/url', 'Magento_Customer/js/customer-data'], function ($, url, customerData) {
    $('.towishlist').on('click', function (event) {
        event.preventDefault();
        var linkUrl = url.build('frontname/controller/action?isAjax=true');
        console.log(linkUrl);
        $.ajax({
            url: linkUrl,
            type: "POST",
            data: {
                imageID: 'imageID'
            },
            showLoader: true,
            dataType: "json",
        }).done(function (data) {
            return function () {
                var msg = 'Success Message';

                customerData.set('messages', {
                    messages: [{
                        type: 'success',
                        text: msg
                    }]
                });
                alert("Here It is ");

            }
        });
    });
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.