ajax请求里的contentType: "application/json"作用

对于页面中复杂数据的提交:

$.ajax({
type:"post",
url:url,
dataType: "json",
contentType: "application/json",
async:true,
data:JSON.stringify(param),
success:function(result){
if(result.code == "0"){
var rows = result.data;
if(typeof successcallback == 'function'){successcallback(rows);}else{alert(result.msg);}
}else{
alert(result.msg);
}
},
error:function(jqXHR, textStatus, errorThrown){
//alert("提交失败,请重试!");
}
});

需要通过JSON.stringify(param)把页面中获取的参数变成json字符串,,此时需要加上contentType: "application/json",

原文地址:https://www.cnblogs.com/fu-fu/p/7261870.html