R
R
RuhHost2021-07-09 13:45:53
JavaScript
RuhHost, 2021-07-09 13:45:53

How to make xmlhttprequest progress bar JS?

function AppGetDataF1(url) {
  var xhr = new XMLHttpRequest();
  
  xhr.open('GET', url, false);
  xhr.send();



  if (xhr.status != 200) {
    return false;
  } else {
    return xhr.responseText;
  }

}

There is such a code for loading pages, tell me how to emit a progress bar or at least any other loading indicator in the form of text?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Gorelov, 2021-07-09
@Kirill-Gorelov

function AppGetDataF1(url) {
document.getElementById('ID_ELEMENT_LOADER').style.display = "block";
  var xhr = new XMLHttpRequest();
  
  xhr.open('GET', url, false);
  xhr.send();



  if (xhr.status != 200) {
document.getElementById('ID_ELEMENT_LOADER').style.display = "none";
    return false;
  } else {
document.getElementById('ID_ELEMENT_LOADER').style.display = "none";
    return xhr.responseText;
  }

}

ID_ELEMENT_LOADER - some text or block, whatever you want.
The fastest solution in 2 minutes....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question