1

The loader widget allows a developer to block page content while an AJAX request is ongoing. The devdocs describes it as:

The Loader widget blocks page content (all content or a part of it).

I'm having trouble figuring out how to block "a part of it."

By using showLoader: true in jQuery AJAX calls, you can have the widget automatically show and hide the loader through the lifetime of the request. Further, the loaderContext property is supposed to give the ability to have the loader appear in a specific area on the site - which seems like a good lead. (You can see an example in the reviews processing JS).

$.ajax({
 url: url,
 showLoader: true,
 loaderContext: $('.elem')
 // snip
)};

This doesn't work at all, in my experience – I just get a warning of Expected to start loader but did not find one in the dom when I use my own element there.

What gives? Do I need to make another instance of the Loader widget for every section I want it to hide?

asked Jul 30, 2020 at 18:27
2
  • I also facing same. Did you solve this problem? Commented Aug 16, 2021 at 11:38
  • No, sorry. But I do know Magento 2 better since I asked this question! Looking at the JS code for lib/web/mage/loader.js, I can see that context only just calls trigger('processStart'); on the element passed to the setting. That shows me that you probably do have to instantiate a new Loader widget. Commented Aug 17, 2021 at 12:17

1 Answer 1

0

try this, I have this working on my code and it seems to be the easiest way to have the loader going nicely

 $.ajax({
 url: url,
 beforeSend: function () {
 $('body').trigger('processStart');
 },
 success: function (res) {
 // snip 
 $('body').trigger('processStop');
 }
 )};
answered Jul 30, 2020 at 19:21
2
  • Not sure if you read the question - I want to have the loader activate on a specific part of the page. This would activate it on the body, which I do not want. Commented Jul 30, 2020 at 20:10
  • 1
    I thought you were trying to freeze your screen, I overlooked the fact you wanted to freeze a specific part. I’ll have another go likely this weekend Commented Jul 30, 2020 at 20:33

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.