How to show loader widget in ajax call Magento 2?

You can show/hide Ajax Loader in Magento Request using Built-in Magento Widget while working with ajax related stuff in the browser.

You can start the loader once the ajax request is started and you can stop the loader widget after the response is getting or failed.

Its simple to add loader widget icon for an ajax request.

You can start loader widget by calling below line,
jQuery(‘body’).trigger(‘processStart’);

You can disable loader widget icon by below line,
jQuery(‘body’).trigger(‘processStop’);

Full example to call Loader Widget in AJAX call,

<script>
    require(['jquery','domReady!'], function ($, urlBuilder, $t) {
        // start loader
        $('body').trigger('processStart');
        $.ajax({
            url: urlString,
            data: {},
            type: 'POST',
            dataType: 'json',
        }).done(function (response) {
        	//stop loader
            $('body').trigger('processStop');
        }).fail(function (response) {
        	//stop loader
            $('body').trigger('processStop');
        });
    });
</script>