0

I have done everything mentioned in this post, however, it gives me an error in console:

require.js:166 Uncaught Error: Mismatched anonymous define() module: function ($, getTotalsAction, customerData) {

$(document).ready(function(){
$(document).on('change', 'input[name$="[qty]"]', function(){
    var form = $('form#form-validate');
    $.ajax({
        url: form.attr('action'),
        data: form.serialize(),
        showLoader: true,
        success: function (res) {
            var parsedResponse = $.parseHTML(res);
            var result = $(parsedResponse).find("#form-validate");
            var sections = ['cart'];

            $("#form-validate").replaceWith(result);

            // The mini cart reloading
            customerData.reload(sections, true);

            // The totals summary block reloading
            var deferred = $.Deferred();
            getTotalsAction([], deferred);
        },
        error: function (xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");
            console.log(err.Message);
        }
    });
   });
  });
}

No idea how to solve this...

UPDATE:

I am not using a custom module, all the code is being added to the custom theme directory.

  • Are you creating custom js for your module? – Ajithkumar Dec 12 '18 at 17:34
  • No, I am not. The reference material never mentioned a post. All the changes are made in the custom theme. – Greg Dec 13 '18 at 9:08
  • try require instead of define – Ajithkumar Dec 13 '18 at 9:12
  • If you take a look a the js.phtml file, there is a require already added above the whole js document. – Greg Dec 13 '18 at 9:18
2

You can follow steps given below to resolve the issue.

step 1) Please move the custom.js file

To

app/design/frontend/Vendor/customtheme/Magento_Theme/web/js

step 2) Update your requirejs-config.js as given below

var config = {
   map: {
    '*': {
        custom:'Magento_Theme/js/custom'
    }
  }
};

step 3) Please update js.phtml located under /app/design/frontend/Vendor/customtheme/Magento_Theme/templates/

File : js.phtml

<script>
require ([
        'jquery',
    ],
    function ($) {
       $(window).on("load", function () {
            require([
                'custom'
            ]);
        });
    });
</script>    

Please remove static content (sudo rm -rf pub/static/frontend/*) and flush cache

  • It actually worked... what is the reason why it didn't work the other way? – Greg Dec 13 '18 at 14:43
  • The reason is custom.js file location was not correct. that's why it was not working properly. – Pritam Info 24 Dec 14 '18 at 10:14
  • I did what you said but it didn't work for me – Chintan Kaneriya Dec 17 '18 at 6:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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