Skip to content

Instantly share code, notes, and snippets.

@mpj
Created November 7, 2010 21:37
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 mpj/666870 to your computer and use it in GitHub Desktop.
Save mpj/666870 to your computer and use it in GitHub Desktop.
Dirt simple example
function on_file_input_element_changed() {
var my_file_input_element = my_method_to_find_file_input_element();
var file = my_file_input_element.files[0];
var xhr = new XMLHttpRequest();
var is_async = true;
xhr.open("POST", "/upload", is_async);
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.setRequestHeader("X-File-Name", encodeURIComponent(file.fileName));
xhr.setRequestHeader("Content-Type", "application/octet-stream");
xhr.onreadystatechange = function(){
if (xhr.readyState == 4)
alert("upload complete!");
}
xhr.send(file);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment