I am trying to make a file loader using HTML5 with a progress bar. Here is my code:
<!DOCTYPE html> <html> <head> <title>Test Progress Meter</title> <script type="text/javascript"> function submitFile(){ var blobOrFile = document.getElementById("fileInput").files[0]; var xhr = new XMLHttpRequest(); xhr.onload = function(e) { alert("finished!"); }; xhr.upload.onprogress = function(e) { if (e.lengthComputable) { document.getElementById("statusBox").innerHTML = e.loaded + " / " + e.total; } }; xhr.open('POST', 'test.php', true); xhr.send(blobOrFile); }; </script> </head> <body> <input type="file" id="fileInput" onchange="submitFile();" /> Status: <span id="statusBox"></span> </body> </html>
Basically, in all my browsers, when I select a file to download, the progress event is triggered and immediately shows the entire transfer as completed. Then it sits there while the file actually loads and, depending on the file, after a few seconds / minutes, warns the script and shows the correct answer from the server.
Am I missing something obvious? As far as I can see, this happens in all my browsers (IE10, Chrome 28, FF22).
source share