JSFiddle - React, Tailwind, and code Playground
HTML
<div class="loader" style="display: none;">
hello world
</div>
JavaScript
$('.loader').show();
p1 = "";
var url = "myURL.ashx?p1=" + p1;
if (GetRequestReturnStatus(url)) {
window.open(url);
}
function GetRequestReturnStatus(url, callback) {
var http = new XMLHttpRequest();
http.onreadystatechange = function() {
if(http.readyState == 4) { //done loading
hideLoader();
}
};
http.open('HEAD', url, false);
http.send();
if (http.status == 404 || http.status == 403 || http.status == 500) {
console.log("nFailure", "some message");
return false;
}
return true;
}
function hideLoader() {
$('.loader').hide();
}