I'm trying to create an ajax based upload form with progress bar. This is my code (the upload part of it):
$xhr = new XMLHttpRequest();
$xhr.upload.addEventListener("progress",
function(e) {
if (e.lengthComputable) {
$progress = (e.loaded / e.total) * 100;
$('#file-progress').css('width', $progressWidth * (e.loaded / e.total));
$('#percentage').html($progress.toFixed(2) + '%');
} else {
alert('Y U NO WORK?');
}
}
, false);
$xhr.onreadystatechange = function(e){
if($xhr.readyState == 4) {
//i'll add this later
}
};
$xhr.open('POST', 'handler.php', true);
var $data = new FormData();
$data.append('file', $file.files[0]);
$xhr.send($data);
Everything works in Chrome (the progress bar and file upload) but in Firefox works only file upload without the progress bar. No errors, nothing. Firefox ignores the progress listener and i can't get why because as i have read Firefox should support XMLHttpRequest level 2.