Last active
April 14, 2017 02:12
-
-
Save jacobtwlee/bf669253a22691cef733 to your computer and use it in GitHub Desktop.
Uploading the file with AJAX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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