I'm trying to catch the natural submission of this form and submit it with AJAX instead.
<form name="input_form" class="input_form" method="post" action="input?nmap_xml" enctype="multipart/form-data">
<input name="input_file" type="file">
<input name="blah" type="text">
<input value="Submit" name="submit" type="submit">
</form>
Here is how I'm AJAX posting the form:
$(document).on('submit', '.input_form', function(e){
$.ajax({
type: "POST",
url: $(this).attr('action'),
data: $(this).serialize(),
success: function() {
alert();
}
});
e.preventDefault();
e.stopPropagation();
});
It "works" except for the fact that the file input is not passed (not even the key name
is passed, it's just ignored). The blah
text input is passed fine.
EDIT: The question this is supposedly a duplicate does not provide an answer to the question I am asking, although admittedly the title suggest it does.
A hint to a possible answer is giving in the very last comment of the answer, as pointed by user ahrim
, namely to use enctype="form/multipart"
. Unfortunately this doesn't work and my problem is exactly the same with that enctype
.