Magento – how to update cart items using ajax

cartmagento-1.9quantity

I need to update quantity of cart items without reloading whole page(using ajax) but with simple code not a lengthy method.
anybody please help me out.

Best Answer

Use below code:

<script>
jQuery(document).ready(function(){
jQuery('.btn-update').on('click',
        function(e){
            e.preventDefault();
            var form = jQuery(jQuery(this).closest('form'));

            // we'll extract the action and method attributes out of the form

            // kick off an ajax request using the form's action and method,
            // with the form data as payload
            jQuery.ajax({
                url: form.attr('action'),
                method: form.attr('method'),
                data: form.serializeArray()
            });
        }
    );
});
</script>

Hope it will helpful to you.