Skip to content

Instantly share code, notes, and snippets.

@agreen757
Created February 4, 2015 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agreen757/597934d36a2f7dbb9ec9 to your computer and use it in GitHub Desktop.
Save agreen757/597934d36a2f7dbb9ec9 to your computer and use it in GitHub Desktop.
Reading the progress stream on uploads - basis of using progress animations
$.ajax({
url: '/fileUpload',
type: 'POST',
data: formData,
xhr: function(){
var xhr = new window.XMLHttpRequest();
//Upload progress
xhr.upload.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total *100;
//Do something with upload progress
console.log(percentComplete);
console.log($('#progress'))
//$('#progress').attr('aria-valuenow',percentComplete)
$('#progress').html(percentComplete)
}
}, false);
//Download progress
xhr.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
//Do something with download progress
//console.log(percentComplete);
//$('#progress').attr('aria-valuenow',percentComplete)
}
}, false);
return xhr;
},
processData: false,
contentType: false,
success: function(data){
console.log(data);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment