Magento 2: Show Loader till Ajax Call not Completed
For Ajax requests in Magento 2, you can show loader on the pages as the request may take less or more time based on the data to be fetched, processing time, server types, etc. The primary benefit of showing loader on Ajax call in Magento 2 is let people know the request in progress and the response is awaited. On Ajax call, the loader can be started and immediately after the response is received, it can be stopped.
You can show loader till ajax call is not completed in Magento 2 to restrict users perform any other activity until the response is received. Today, I have come up with the implementation of it.
Code to Show Loader till Ajax Call is not Completed in Magento 2:
1 2 3 4 5 6 7 8 |
jQuery.ajax({ url: url, type: 'POST', dataType: 'json', showLoader: true //use to display loader }).done(function (data) { return true; }); |
1 |
jQuery(‘body’).trigger(‘processStart’); |
1 |
jQuery(‘body’).trigger(‘processStop’); |
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
How to Get Static Block Content in Block File in Magento 2
How To Fix “Indexer Reindex Required” Error In Magento 2
Next