I want to add loader animation when a fetch API request is loading data. Tried the old jQuery way, but it does nothing for fetch requests.
jQuery(document).ready(function($){
$(document).on({
ajaxStart: function() { $(document.body).addClass("loading"); },
ajaxStop: function() { $(document.body).removeClass("loading"); },
ajaxError: function() { $(document.body).removeClass("loading"); }
});
});
I want to add this loader when any fetch API request is made, not only for one particular fetch API request, similarly, like the jQuery code above does. It adds\removes class loading when any XMLHtppRequest has started/stopped.
Is there any way of doing this with fetch requests?