Skip to content

Instantly share code, notes, and snippets.

@jacobtwlee
Last active April 14, 2017 02:12
Show Gist options
  • Save jacobtwlee/bf669253a22691cef733 to your computer and use it in GitHub Desktop.
Save jacobtwlee/bf669253a22691cef733 to your computer and use it in GitHub Desktop.
Uploading the file with AJAX
function sendFile(fileData) {
var formData = new FormData();
formData.append('imageData', fileData);
$.ajax({
type: 'POST',
url: '/your/upload/url',
data: formData,
contentType: false,
processData: false,
success: function (data) {
if (data.success) {
alert('Your file was successfully uploaded!');
} else {
alert('There was an error uploading your file!');
}
},
error: function (data) {
alert('There was an error uploading your file!');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment