I have to update the main cart on change of quantity by Ajax without click on "Update Cart Button" and without reloading the page.
By the following code, I'm able to update cart table but m not getting a solution to update the "Cart Summary" block.

require(['jquery', 'Magento_Customer/js/customer-data',
    'jquery/jquery-storageapi'], function ($) {
    // $("#submitbutton").hide();
    var form = $('form#form-validate');
    var qtyfields = $('input.qty');
    $('.page.messages').each(function () {
        var thismessage = $(this);
        thismessage.attr('id', 'messages');

    form.find(qtyfields).each(function (e) {
        var thisfield = $(this);
        $(this).change(function () {
            console.log('change detected');

    form.on('submit', function (e) {
            url: form.attr('action'),
            data: form.serialize(),
            type: 'post',
            success: function (res) {
                var parsedResponse = $.parseHTML(res);
                var result = $(parsedResponse).find("#form-validate");
            error: function () {
        console.log('form submitted');

Please give me some solution.

2 Answers 2


Use this one, it works fine for me:

  • var parsedResponse = jQuery.parseHTML(res);
  • var result = jQuery(parsedResponse).find(".subtotal");
  • var result1 = jQuery(parsedResponse).find(".message");
  • jQuery(".subtotal").replaceWith(result);
  • jQuery(".message").replaceWith(result1);

This code only will submit once if call the


And Ajax returning a whole HTML page for the result.

Is there any way to just get back small string of a JSON data set instead ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.