I am trying to add a simple progress bar/number to my PHP image upload. If javascript is enabled, this script shall work, but now, it immediatly shows 100%, before everything has been uploaded, and then it shows "images are beeing processed", also too early, I think.
Something must be wrong:
$('form#uploadform').submit(function(){ var formdata = $('form#uploadform').serialize(); $('p.isloading').show(); $.ajax({ xhr: function () { var xhr = new window.XMLHttpRequest(); xhr.upload.addEventListener("progress", function (evt) { if (evt.lengthComputable) { var percentComplete = evt.loaded / evt.total; $('#uploadprogress').text(percentComplete * 100 + '%'); } }, false); xhr.addEventListener("progress", function (evt) { if (evt.lengthComputable) { var percentComplete = evt.loaded / evt.total; $('#uploadprogress').text(percentComplete * 100 + '%'); } }, false); return xhr; }, type: 'POST', url: "/upload", data: formdata, success: function (data) { $('#uploadprogress').text('images are being processed'); } }); //return false; }); I want a simple way to show how much is already uploaded, but it seems I am doing it wrong. Any help is appreciated.