There is such a function of processing download stages. Now, when a file is uploaded to the server, a block with animation is displayed, at the end the block is removed and a notification about the successful upload is displayed. But in the case of multiple loading, the block is removed after the first downloaded file and the notification is displayed after each loaded file. How can I change this function so that the block with animation was removed, and the notification was displayed only after downloading all the files?
function uploadFile(file){ var url = "/upload"; var xhr = new XMLHttpRequest(); xhr.upload.onprogress = function(){ $('.loader').show(); } xhr.upload.onload = function() { $('.loader').hide(); (function Notification() { var notification = new NotificationFx({ message : "<p>Фотографии загружены</p>", layout : "growl", effect : "jelly", type : "success", }); notification.show(); })(); } var fd = new FormData(); xhr.open("POST", url, true); xhr.onreadystatechange = function() { if (xhr.readyState == 4 && xhr.status == 200) { console.log(xhr.responseText); // handle response. } }; fd.append('uploaded_file', file); xhr.send(fd); }