Skip to content

Instantly share code, notes, and snippets.

@amirkhiz
Created January 6, 2019 14:46
Show Gist options
  • Save amirkhiz/f75d398ab723d954c19f4c56ee64d548 to your computer and use it in GitHub Desktop.
Save amirkhiz/f75d398ab723d954c19f4c56ee64d548 to your computer and use it in GitHub Desktop.
Send file with ajax request in form data
$('#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