Created
February 4, 2015 16:13
-
-
Save agreen757/597934d36a2f7dbb9ec9 to your computer and use it in GitHub Desktop.
Reading the progress stream on uploads - basis of using progress animations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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