Skip to content

Instantly share code, notes, and snippets.

@LulzAugusto
Created June 25, 2014 19:26
Show Gist options
  • Save LulzAugusto/8e1391202873aeb560cc to your computer and use it in GitHub Desktop.
Save LulzAugusto/8e1391202873aeb560cc to your computer and use it in GitHub Desktop.
How to setup a jQuery Ajax request to upload file(s)
var fileField = document.getElementById("file_picker");
var file = fileField.files[0]; // Use multiple attr in your input field to upload more than one file
var formData = new FormData();
formData.append('filecsv', file, file.name);
$.ajax({
type: "POST",
url: "",
processData: false,
contentType: false,
dataType: 'text',
data: formData,
})
.done(function(data) {
// do stuff
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment