the server responded with a status of 415 ()

https://blog.csdn.net/mameng1988/article/details/91554993

 

今天前端遇到错误代码:

Failed to load resource: the server responded with a status of 415 (Unsupported Media Type)
  • 1

因为我们后端使用的是:Spring的@RequestBody接受java对象,所以首先我们要知@RequestBody 是用来干嘛的:接受一个JSON’字符串’;注意是‘字符串’不是JSON对象,如果有与之对应的java实体,会帮助自动转化成java对象。
下面是我遇到的415的错误代码:
前端一个非常简单的代码:

var people= { "name":1, "age":2 } $.ajax({ url:"people/test/delPeopleByPrimaryKey", type:'POST', contentType: "application/x-www-form-urlencoded; charset=utf-8", dataType:'json',//json 返回值类型 data: JSON.stringify(people),//转化为json字符串 success:function(data){ } });

posted @ 2023-02-14 14:41  A汉克先生  阅读(123)  评论(0编辑  收藏  举报