Skip to content

Instantly share code, notes, and snippets.

@sesopenko
Last active December 11, 2015 10:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sesopenko/4587842 to your computer and use it in GitHub Desktop.
Save sesopenko/4587842 to your computer and use it in GitHub Desktop.
Example code for an ajax file upload with jQuery and HTML5.
if(window.FormData){
var formData = new FormData($('form#uppic', $('div#upload'))[0]);
$.ajax({
url:'/upload/'+gUUID,
type:'POST',
xhr:function(){
var myXhr = $.ajaxSettings.xhr();
if(myXhr.upload){//check if upload property exists
myXhr.upload.addEventListener('progress', sendpic.progressHandle);
}
return myXhr;
},
success:sendpic.sendsuccess, //function that will receive unparsed string
error:sendpic.senderror, //function that will receive an error object
data:formData,
cache:false, //important
contentType:false, //important
processData:false //important
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment