Created
January 6, 2019 14:46
-
-
Save amirkhiz/f75d398ab723d954c19f4c56ee64d548 to your computer and use it in GitHub Desktop.
Send file with ajax request in form data
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
$('#frm-human-res').submit(function (e) { | |
e.preventDefault(); | |
var form_data = new FormData(), | |
cv_file = document.getElementById("upload-btn").files[0]; | |
var other_data = $(this).serializeArray(); | |
$.each(other_data, function (key, input) { | |
form_data.append(input.name, input.value); | |
}); | |
form_data.append('file', cv_file); | |
$.ajax({ | |
url: $(this).attr('action'), | |
method: 'POST', | |
processData: false, | |
contentType: false, | |
data: form_data, | |
success: function (result) { | |
$('body').append(result); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment