I use the ajaxuploader.js to upload pictures.
i use the following piece of code to get the progress of the ajax request:
jQuery(function($) {
$.ajaxUploadSettings.name = 'uploads[]';
$('#pic-upload-area').ajaxUploadPrompt({
type: 'POST',
url: "myUrl",
beforeSend: function() {
// do sth
},
error: function(data) {
// do sth
},
success: function(data) {
// do sth
},
xhrFields: {
onprogress: function(progress) {
var percentage = Math.floor((progress.total / progress.totalSize) * 100);
console.log('progress', percentage);
if (percentage === 100) {
console.log('DONE!');
}
}
},
});
});
Seems to work, at the ende it logs "process 100" and "DONE!".
But whats with the percentages between 0 and 100? Seems the eventlistener doesnt work properly and fires evry x ms and gets me the current percentage of the upload.