How to make a progress bar.

Guys, how to make a download of some type. (A standard JQUERY Ajax function)
Clicking the button shows LOADING... Then it's simple. beforeSend: function(){}
BUT!
maybe the server can respond immediately, and maybe you think that would do to the inscription LOADING always burning not less than 3 seconds. That is 3 to server response.
Does it really make, or have timers and functions to prescribe?
June 3rd 19 at 19:30
2 answers
June 3rd 19 at 19:32
Use Promise.all for two promises:
  • The first will be to upload (jQuery.ajax() returns a jqXHR which is always method, it will call the resolve())
  • The second is the setTimeout() with retracting labels and call resolve() with the desired delay
June 3rd 19 at 19:34
So? Codepen

$('body').text('Loading...');
makeAjax(function(data) {
 $('body').html(function() {
 var result = ";
 for (var user in data) {
 result += '<div>'+ data[user].name + ' (' + data[user].email +')</div>';
}
 return result;
}());
});

makeAjax function(done) {
 return $.ajax({
 url: 'https://jsonplaceholder.typicode.com/users',
 method: 'GET',
 dataType: 'json',
 success: function(data) {
 setTimeout(function() {
 if (done) done(data);
 }, function(min, max) {
 return Math.random() * (max - min) + min
 }(2e3, 3e3));
}
});
}

Find more questions by tags jQuery