Magento 2 – Ajax Add to Cart Button in Product Detail Page

addtocartmagento-2.1magento-communitymagento2

I have check online demo of Magento 2
http://magento2-demo.nexcess.net/fusion-backpack.html
when we click on add to cart it add product via AJAX but i have Set up demo on localhost it don't to add Product to cart via AJAX.

Can anyone tell where is settings to enable ajax on add to cart ?

Best Answer

You have to just override addtocart.phtml file

app/design/frontend/Packagename/themename/Magento_Catalog/templates/product/view/addtocart.phtml

Replace "bindSubmit": false to "bindSubmit": true

<script type="text/x-magento-init">
    {
        "#product_addtocart_form": {
            "catalogAddToCart": {
                "bindSubmit": false
            }
        }
    }
</script>

to

<script type="text/x-magento-init">
    {
        "#product_addtocart_form": {
            "catalogAddToCart": {
                "bindSubmit": true
            }
        }
    }
</script>

Remove cache and check its in detail page.

Related Topic