How can I easily implement "formData" in this ajax call?
HTML:
<form id="insertDocument" action="#" enctype="multipart/form-data">
<input type="file" id="file" name="file" />
<select name="type_d" id="type_d">
<option value="1">something</option>
<option value="2">something</option>
<option value="3">something</option>
<option value="3">something</option>
<option value="3">something</option>
</select>
<input type="text" name="description_d">
<input type="date" name="date_d">
<input type="date" name="valid_d">
<input type="submit" value="Upload document" id="insert_d">
</form>
jQuery:
$("#insert_d").click(function() {
event.preventDefault();
var data = $("#insertDocument").serialize();
$.ajax({
type: 'POST',
url: 'insertDocument.php',
data: data,
success: function(html){
console.log(html);
}
});
});
My problem is, that I need to post all the data - file and other inputs. Do I have to combine formData with serialize?