I have my code almost functional but the event listener Progress isn't firing and so i am unable to track the progress of my upload.
The event listener Load is firing and the rest of my code is executing so I'm at a loss. Does anyone have any suggestions?
$(#myForm).submit(function(){
var xhr = new XMLHttpRequest();
//Progress Tracking
xhr.upload.addEventListener(progress, function(e){
if(e.lengthComputable){
alert('test');
var percentage = Math.round((e.loaded * 100) / e.total);
$(#myProgress).innerHTML(percentage + '%');
$(#Progress).val(percentage);
}
}, false);
//Added just to test that something was firing.
xhr.addEventListener(load, function(){alert('load');}, false);
xhr.addEventListener(error, function(){alert('error');}, false);
xhr.addEventListener(abort, function(){alert('abort');}, false);
//Status Tracking
xhr.open(this.method, this.action, true);
xhr.setRequestHeader(X-FILENAME, this.name);
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.status == 200){
$('#myForm')[0].reset();
}
};
//Submit Data
var fd = new FormData();
fd.append(text, $('#text').val());
fd.append(file, $('#file')[0].files[0]);
xhr.send(fd);
return false;
});