0

I am wondering how does the remove wishlist button work?

i have checked the code, and there is no form tag around it.

How can it post to the remove item controller in vendor/magento/module-wishlist/Controller/Index/Remove.php

enter image description here

<div class="actions-secondary">
    <a href="#" data-bind="attr: {'data-post': delete_item_params}" title="Remove This Item" class="btn-remove action delete" data-post="{&quot;action&quot;:&quot;http:\/\/m226.test\/wishlist\/index\/remove\/&quot;,&quot;data&quot;:{&quot;item&quot;:&quot;2&quot;,&quot;uenc&quot;:&quot;aHR0cDovL20yMjYudGVzdC93aXNobGlzdC9pbmRleC9pbmRleC93aXNobGlzdF9pZC8xLw,,&quot;}}">
        <span>Remove This Item</span>
    </a>
</div>
2
  • 1
    It uses ajax call with knockout js. As you can see syntax with data-bind and data-params on a tag. Nov 27, 2018 at 3:40
  • @devHarry please check my ans Nov 27, 2018 at 9:21

1 Answer 1

1

Magento remove wishlist button uses AJAX call with knockout.js.

You can see remove button syntax with data-bind and data-params on a tag.
Using the data-params it will call action path "http://m226.test/wishlist/index/remove/" and complete the remove wishlist item process with use of "/wishlist/index/remove" controller.

Also you can use something like this to remove wishlist using jQuery.

jQuery(".wishlist-link .removeWishlist").click(function(e){
            e.preventDefault();
            var actiondata = jQuery.parseJSON(jQuery(this).attr('data-post'));
            var addurl = actiondata.action;
            var data = actiondata.data;
            data['isAjax'] = true;
            jQuery.ajax({
                showLoader: true,
                url: addurl,
                data: data,
                type: "POST",
                dataType: 'json'
            }).done(function (data) {
                console.log(data);
            });
            return false;
        });
2
  • would you please provide a simple example about if i have a custom module in Magento 2 with the delete action, then how can i make the ajax call to the action like the remove wishlist, thank you
    – devHarry
    Nov 27, 2018 at 20:09
  • Please check my updated ans. Nov 28, 2018 at 4:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.