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.
2 Answers
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.
-
When i am refreshing cart page it's updating cart not on click of "Update" button.– MagecodeCommented Aug 24, 2017 at 6:47
For this you can refer http://excellencemagentoblog.com/blog/2011/10/04/magento-add-product-to-cart-ajax/ this url or some of the free extension are also available for this like
1) https://www.magentocommerce.com/magento-connect/ajax-cart-popup.html
2) https://www.magentocommerce.com/magento-connect/ajax-add-to-cart-4.html
3) https://www.magentocommerce.com/magento-connect/ajax-mini-cart-ajax-cart.html
4) https://www.magentocommerce.com/magento-connect/ajax-filter-and-cart-1.html
Hope this will help you.
a lengthy method.
you cannot do it