Skip to content

Instantly share code, notes, and snippets.

@stgoos
Forked from jacobtwlee/SendFile.js
Created January 15, 2017 15:12
Show Gist options
  • Save stgoos/0a0080e77fb2b2fc0d445ccd7e8fa173 to your computer and use it in GitHub Desktop.
Save stgoos/0a0080e77fb2b2fc0d445ccd7e8fa173 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