Friday, 29 January 2016

No data sent when posting form using jQuery $.ajax?

Indications: form is submitted using jQuery $.ajax and method is set to POST.

contentType: false

Unless the contentType is set to false jQuery mucks up the the boundary value. If the submittable data from form is prepared using FormData the browser will do it the right way.

var subData = new FormData(($("#formSelector")));;
url: "/index.php",
type: 'POST',
data: subData,
processData: false,
contentType: false,//jQuery fucks this up
xhrFields: { withCredentials:true },
success: function(data){
fail: function(){