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

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

$.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

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

相关文章
相关标签/搜索