1.找了好久发现contentType一般为默认的application/x-www-form-urlencoded,这次post请求后台限定了为application/json
2.当设置contentType为application/json还是出错时,把data也要转换一下
$.ajax({ method: "POST", url: "", contentType: 'application/json', data:JSON.stringify({ "id": id }), success: function( data ) { } });
jquery ajax 设置请求头header 参数
$.ajax( { url:'http://127.0.0.1:30080/api-a/quasiCustom/selectCustomList', type:'post', dateType:'json', beforeSend: function(xhr) { xhr.setRequestHeader("organId:'1333333333'"); }, headers:{'Content-Type':'application/json;charset=utf8','organId':'1333333333'}, data:JSON.stringify(org), success:function(data){console.log("sucess");}, error:function(data){console.log("error");} } );
标签:jquery,function,contentType,application,ajax,header,json,data From: https://www.cnblogs.com/daboluo/p/17317492.html