Skip to content

Instantly share code, notes, and snippets.

@d33pfri3d
Created June 8, 2012 13:30
Show Gist options
  • Save d33pfri3d/2895625 to your computer and use it in GitHub Desktop.
Save d33pfri3d/2895625 to your computer and use it in GitHub Desktop.
Form data - Files > XHR
var formData = new FormData()
for (var i = 0; i < files.length; i++){
formData.append('file', files[i]);
}
//new post a new XHR request
var xhr = new XMLHttpRequest();
xhr.open('POST', url);
xhr.upload.onprogress = function (event){
if (event.lengthComputable) {
var complete = (event.loaded / event.total * 100 | 0);
progress.value = complete;
}
}
xhr.send(formData);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment