I am building a website, that has a career page with Input File HTML Control for Resume uploading. While using JQuery to POST the form values to an ASPX Page, Everything works fine except File uploading. How can I Use JQuery to Post every fields (including files) in one AJAX request ? The example I see in Google are handling only the file uploading, not other fields with it. This is my JQuery, ASPX for file upload not made.
<script type="text/javascript">
$(document).ready(function(e) {
// File variable
var files;
// Add events
$('#resume').on('change', prepareUpload);
// Grab the files and set them to our variable
function prepareUpload(event)
{
files = event.target.files;
}
$( "#submit_btn" ).click(function( ) {
var fileData = new FormData();
$.each(files, function(key, value)
{
fileData.append(key, value);
});
var formMessage = tinyMCE.get('message').getContent();
var formName = $('.contact-container #name').val();
var formPhone = $('.contact-container #phone').val();
var formEmail = $('.contact-container #email').val();
var formApplyFor = $('.contact-container #applyfor').val();
// Get some values from elements on the page:
var a= $.ajax({
method: "POST",
url: "mail/test.aspx",
processData: false,
contentType: false,
data: {
form: 'career',
name: formName ,
phone: formPhone,
email: formEmail,
applyfor: formApplyFor,
resume: fileData,
coverletter: window.btoa(unescape(encodeURIComponent( formMessage)))
},
success: function (data) {
alert('success');
},
error: function (data) {
alert('err');
}
})
.done(function( msg ) {
alert('done');
}); //ajax end
alert(a);
}); //submit button end
}); //document ready end
</script>
