fix upload estimation

This commit is contained in:
Milan
2018-12-10 13:06:41 +01:00
parent f27c176368
commit 7449b53667

View File

@@ -56,7 +56,7 @@ function uploadFile(uploadButton){
hideFinished(); hideFinished();
hideError(); hideError();
showProgress(); showProgress();
$.ajax({ var request=$.ajax({
url: 'audio_recordings.cgi', url: 'audio_recordings.cgi',
type: 'POST', type: 'POST',
data: new FormData($('#audio_recordings_upload')[0]), data: new FormData($('#audio_recordings_upload')[0]),
@@ -65,11 +65,12 @@ function uploadFile(uploadButton){
processData: false, processData: false,
xhr: function() { xhr: function() {
var start = new Date(); var start = new Date();
var myXhr = $.ajaxSettings.xhr(); //var myXhr = $.ajaxSettings.xhr();
if (myXhr.upload) { var xhr = new window.XMLHttpRequest();
if (xhr.upload) {
var c=0; var c=0;
var oldRemaining=0; var oldRemaining=0;
myXhr.upload.addEventListener( xhr.upload.addEventListener(
'progress', 'progress',
function(data) { function(data) {
if (!data.lengthComputable) return; if (!data.lengthComputable) return;
@@ -102,15 +103,19 @@ function uploadFile(uploadButton){
false false
); );
} }
return myXhr; return xhr;
}, }
}).error( });
request.fail(
function(jqXHR, textStatus, errorThrown ){ function(jqXHR, textStatus, errorThrown ){
showError("error: "+errorThrown); showError("error: "+errorThrown);
hideProgress(); hideProgress();
hideFinished(); hideFinished();
} }
).done( );
request.done(
function(data){ function(data){
showFinished(); showFinished();
hideProgress(); hideProgress();