问题
I am sending formData or Json to server. So i need contentType for formData. Please don't give false as contentType value.
formdata = new FormData(form[0]);
$.ajax({
url: url,
data: formdata? formdata :$(#User).serialize(),
type: 'post',
cache: false,
contentType: "json",
processData: false,
beforeSend: function () {
$(options.createOrUpdateRelationship).attr('disabled', 'disabled');
var target = $(options.setupSubContainer);
$("body").append(options.fadeoutDiv);
options.spinner.spin(target[0]);
},
success: function (data) {
}
});
回答1:
Need to give the dataType because in which format sending data to server for example json,array and you can give the formid.serialize() to to serialize the formadatas in a Query string format and send to server you can receive the data by $_POST in php
var form = $("#formId").serialize();
$.ajax({
type: 'POST'
url: url,
data: form,
dataType: 'json',
success: function (data) {
//add your code
}
});
contentType removed - we are not sending JSON.
来源:https://stackoverflow.com/questions/27123238/need-content-type-for-formdata