Form serialize with jquery for ajax post
If you have normal form(like all text fields) to serialize form data use
$("#my-form").serialize();
Beside that if you have form enctype of “multipart/form-data” then use
new FormData(this)
Example:
$('#my-form') .submit( function(e) { var formData = new FormData(this); $.ajax({ url: 'http://url', type: 'POST', data: formData, processData: false, // tell jQuery not to process the data contentType: false // tell jQuery not to set contentType }); e.preventDefault(); });
Ref
https://developer.mozilla.org/en-US/docs/Web/Guide/Using_FormData_Objects