Created
February 27, 2017 15:47
-
-
Save elliotthilaire/7bcd1f06281a4ad6733fd9e237b5067a to your computer and use it in GitHub Desktop.
Upload multipart 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
<%= form_tag project_assets_path(project), multipart: true, class: 'upload-form' do %> | |
<%= file_field_tag 'file' %> | |
<%= submit_tag 'Upload' %> | |
<% end %> |
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
$('.upload-form').on('submit', function(event) { | |
event.preventDefault(); | |
var form = $(event.target); | |
var uploadUrl = form.attr('action'); | |
var formData = new FormData(event.target) | |
$.post({ | |
url: uploadUrl, | |
data: formData, | |
processData: false, | |
contentType: false | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment