Hi,
I have a form which contains some inputs and a file selector. I use the following code for sending file data:
$(document).ready(function () {
$('#submitForm').on('click', function () {
const formData = new FormData();
const file = document.getElementById("myfile").files[0];
formData.append("file", file);
$.ajax({
type: "POST",
url: "/Admin/UploadPm",
contentType: false,
processData: false,
data: formData
});
});
});
And use the following code for saving form inputs (TextBoxes):
$(document).ready(function () {
$('#submitForm').on('click', function () {
$_pmNum = $('#pm-num').val();
$_costCenter = $('#cost-center').val();
$_serviceType = $('#serviceType').val();
$_destination = $('#destination').val();
$_workCenter = $('#workCenter').val();
$_startDate = $('#date-input1').val();
$_endDate = $('#date-input2').val();
var myData = {
pmNumber: $_pmNum,
costCenter: $_costCenter,
serviceType: $_serviceType,
destination: $_destination,
workCenter: $_workCenter,
startDate: $_startDate,
endDate: $_endDate,
}
$.ajax({
type: "POST",
url: "/Admin/UploadPm",
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
data: myData
});
});
});
My problem is that the action method I use takes two input parameters. How can I combine those codes above to send both file and input (TextBoxes) simultanuously?