Snippet of HTML code:
<form id="custom_form" name="custom_upload" method="POST" enctype="multipart/form-data">
<label>Choose File:</label>
<input id="in" name="csv_file" value="Add CSV" type="file" required />
<table class="opttable">
<tr>
<td>
Title<span style="color: red;">*</span>
</td>
<td>
<select id="select1" class="optselect form-control">
<option>abc</option>
<option>cde</option>
</select>
</td>
</tr>
</table>
<input type="submit" value="Submit" class="onsubmit">
</form>
JavaScript section:
$('.onsubmit').on('click', function (e) {
var id = {{id}}
var fd= $('form').serialize()
console.log(fd)
$.ajax({
url: '/someview/'+id,
type: 'POST',
data: fd,
sucess: function(data) {
console.log(data);
},
error: function(err) {
console.log('err: '+err);
}
});
});
This is a code implementation where I am trying to include both file and regular data in an AJAX call. Utilizing the serialize method for converting form data into strings, but wondering how to handle file inclusion along with it.