When a form includes files, the serialize() method on a form element is not going to help you.
The serialize() method serializes a form to json, but all file inputs are not included.
The trick is to use FormData.

var jqueryForm = $("form");
var formAsHtmlElement = jqueryForm[0];
var formData = new FormData(formAsHtmlElement);

The form data can be posted as follows

    type: form.attr("method"),
    url: form.attr("action"),
    data: formData,
    cache: false,
    contentType: false,
    processData: false,
    success: function (data) {

The contentType and processData are very important. This treats the data as “multipart/form-data”.

The following two tabs change content below.
I'm a software developer from Utrecht. Interested in DDD, continuous delivery, new technologies & frameworks.

Latest posts by Vincent Keizer (see all)