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",


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM