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
$.ajax({ 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”.