Skip to content

Instantly share code, notes, and snippets.

@imposibrus
Last active August 29, 2015 14:04
Show Gist options
  • Save imposibrus/ba4e2ce0e689add73f66 to your computer and use it in GitHub Desktop.
Save imposibrus/ba4e2ce0e689add73f66 to your computer and use it in GitHub Desktop.
Upload file with $.ajax()
var fd = new FormData();
fd.append('file', $('input[type="file"]')[0].files[0]);
$.ajax({
url: '/photoUpload',
data: fd,
processData: false,
contentType: false,
cache: false,
type: 'POST',
success: function(data){
console.log(data);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment