Skip to content

Instantly share code, notes, and snippets.

@danharper
Created January 14, 2014 18:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danharper/8423096 to your computer and use it in GitHub Desktop.
Save danharper/8423096 to your computer and use it in GitHub Desktop.
XHR upload progress
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener('progress', function(e) {
var percent = parseInt(e.loaded / e.total * 100, 10)+'%';
console.log('progress', percent);
}, false);
xhr.onreadystatechange = function(e) {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log('done!');
}
}
xhr.open('post', '/path/to/upload/script', true);
xhr.send(image);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment