最近在做项目交互的时候,刚开始向后台传递数据返回 415 ,后来百度添加了 contentType:“application/json“ 之后返回400,然后把传输的数据格式改为json字符串就传输成功了,现在我们来看看 contentType:“application/json“的作用:
添加 contentType:“application/json“之后,向后台发送数据的格式必须为json字符串
$.ajax({ type: "post", url: "mobile/notice/addMessageInfo.jspx", contentType: "application/json", data:"{'name':'zhangsan','age':'15'}", dataType: "json", success: function(data) { console.log(data); }, error: function(msg) { console.log(msg) } })