I created my website using a custom theme, how to implement ajax to my add-to-cart and wishlist button?

I tried the following step, it not working,

vendor\magento\module-catalog\view\frontend\templates\product\view\addtocart.phtml (For testing purpose added in core files)

<script type="text/x-magento-init">
    {
        "#product_addtocart_form": {
            "Magento_Catalog/js/validate-product": {},
            "catalogAddToCart": {
                "bindSubmit": true
            }
        }
    }
</script>
有帮助吗?

解决方案

@zus I would suggest to review the below post where you can get your question answer easily. Here you will find an extension option as well as a customization option. But I would suggest to go with the extension option.

Magento 2 : Add to compare and add to wishlist with ajax

https://www.tigren.com/magento-2-extensions/ajax-suite-magento-2/

Please let me know if this will not help.

许可以下: CC-BY-SA归因
scroll top