Magento – Update cart using Ajax Magento not working

ajaxcartmagento-1.9

<script type="text/javascript">     jQuery(document).ready(function(){ jQuery('#shopping-cart-table')
    .on(
        'change',
        'input[name$="[qty]"]',
        function(){
            var form = jQuery(jQuery(this).closest('form'));    

            jQuery.ajax({
                url: form.attr('action'),
                method: form.attr('method'),
                data: form.serializeArray()
            });
        }
    ); });  </script>

I used this function for the Ajax update cart, ajax request is working but it is not updating in the cart, anybody done this ajax update cart please help me.

Best Answer

Assume that your form action url is checkout/cart/updatePost/ and have no customization at Mage_Checkout_CartController at updatePostAction().

Then you need to understand that the request to checkout/cart/updatePost does not render the cart page content. So if you tried to get the cart page content from the response, it's a waste of time. The response is a 302 redirect after the cart was updated.

So you need to use a customized cart controller.

Also make sure, that the form_key input field is present.

Related Topic