0

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.

Juicy
  • 11,840
  • 35
  • 123
  • 212
  • @ahrim Please remove the duplicate, I was on that post, it's from 2010 and the accepted answer does not provide an up-to-date answer. – Juicy Aug 05 '15 at 14:36
  • the update was on April '14 – ahrim Aug 05 '15 at 14:37
  • @ahrim The updated answer is `With XHR2, File upload through AJAX is supported. E.g. through FormData object, but unfortunately it is not supported by all/old browsers.`. This does not constitute an answer to the question. – Juicy Aug 05 '15 at 14:38
  • The last comment of the answer has a helpful link also. – ahrim Aug 05 '15 at 14:39
  • @ahrim Thank you for your time and help however I must insist, neither the answer nor the last out of those *10* comments provides an answer. The link you mention explains how to get a form working when the only field is the file upload. I'm trying to get *multiple* fields working, with a file among them. – Juicy Aug 05 '15 at 14:45

0 Answers0