Spring mvc下Ajax获取JSON对象问题 406错误
2017-12-20 14:21
513 查看
spring 通过@ResponseBody标签返回JSON数据的方法都报406错: Failed to load resource: the server responded with a status of 406 (Not Acceptable) 以及报错描述: The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ()
Spring 配置如下:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
mediaTypes配置:
atom=application/atom+xml
html=text/html
json=application/json
*=*/*
用@ResponseBody返回对象出现问题,报406错误!!!
最后发现是:spring 时requestedMediaTypes却为[text/html]的情况报406错误,还有一个原因可能是由于采用的后缀有关,如果使用*.htm,*.html等,默认就会采用[text/html]编码,若把AJAX请求URL后面加上*.json,*.shtml等就OK!
Spring 配置如下:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
mediaTypes配置:
atom=application/atom+xml
html=text/html
json=application/json
*=*/*
用@ResponseBody返回对象出现问题,报406错误!!!
最后发现是:spring 时requestedMediaTypes却为[text/html]的情况报406错误,还有一个原因可能是由于采用的后缀有关,如果使用*.htm,*.html等,默认就会采用[text/html]编码,若把AJAX请求URL后面加上*.json,*.shtml等就OK!
相关文章推荐
- Spring mvc 下Ajax获取JSON对象问题 406错误
- var dataObj=eval("("+data+")");//转换为json对象(解决在ajax返回json格式数据的时候明明正确的获取了返回值但是却就是进不去success方法的问题。格式错误)
- Spring mvc 下Ajax获取JSON对象问题 406错误
- springMVC下ajax获取后台参数直接走错误或者报406错误问题解决
- Spring 3.2.* MVC通过Ajax获取JSON数据报406错误
- Spring 3.2.* MVC通过Ajax获取JSON数据报406错误
- Spring 3.2.* MVC通过Ajax获取JSON数据报406错误
- Spring 3.2.* MVC通过Ajax获取JSON数据报406错误
- Spring 3.2.* MVC通过Ajax获取JSON数据报406错误
- Spring Mvc 返回Json对象给前端报 406 (Not Acceptable) 问题解决
- Spring mvc使用注解@ResponseBody Ajax请求返回json报406错误
- Spring 3.2.* MVC通过Ajax获取JSON数据报406错误
- Spring 3.2.* MVC通过Ajax获取JSON数据报406错误
- 关于springMVC 4.x配置ajax-json 出现406错误的问题。
- SpringMVC通过Ajax获取JSON数据报406错误
- Spring 3.2.* MVC通过Ajax获取JSON数据报406错误
- Spring MVC 返回json数据 报406错误 问题解决方案
- 后台ajax调用中字符串到jquery中的json对象和数组对象转换问题
- Spring MVC 4 配置ajax请求返回json数据的问题
- Spring MVC控制器用@ResponseBody声明返回json数据报406的问题