I have implemented Ajax call to add product to cart, which is somewhat like below:

    showLoader: true,
    url: SERVER_URL+'common/custompurchase/addtocart',
    data: data,
    type: "POST",
    dataType: 'json'
}).done(function (data) {
    // some code...

It is working fine. But it's not showing loading icon when i call Ajax. I have also tried below answers.

  1. $('body').trigger('processStart');
  2. $('body').loader('show');
  3. var body = $('body').loader(); body.loader('show');

In console it's showing this warning.

Expected to start loader but did not find one in the dom

Please provide suggestions if anybody has faced such issue.

Note: I have implemented this code on product detail page.

  • Its a default Magento bug you can check this issue on GIT : github.com/magento/magento2/issues/11904 – Amit Naraniwal Feb 11 '19 at 11:54
  • but i have also coded ajax call for some other tasks on different pages. there it works fine. only on this page it does not work. – Khushbu Feb 11 '19 at 12:08
  • Can you please add the screen when you call ajax? – Amit Naraniwal Feb 11 '19 at 12:56

To prevent console log error use Magento default function processStart and processStop for the loader in your ajax.

remove this from your ajax call showLoader: true

         /*showLoader: true, Remove this one */
         url: url,
         data: param,
         type: "POST",
         beforeSend: function () {
             $('body').trigger('processStart'); // start loader
         }).done(function (data) {
             $('body').trigger('processStop');   // stop loader
             return true;

By adding the following HTML code before the ajax call. make sure it renders between <body> and </body>tag

<div class="loading-mask" data-role="loader">
    <div class="loader"> &nbsp;        

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.