1.首先说406的错误是什么,406是不可接受的,此请求所标识的资源只能生成内容特征为“不可接受”的响应体;
2.ajax几个重要的参数:
url:请求的地址,String类型;
data:请求参数,json格式(键值对);
type:请求的类型,post或者get,String类型;
dataType:返回参数类型,这里可以是:json,text,xml,html等
succes:成功回调函数,数据成功返回这里;
error:失败回调函数,数据失败时;
$.ajax({
url:"http://localhost:8080/项目名/类名/方法名.....";
type:"post";
data:{"key1":"value1",......};
dataType:"json";
success:function(data){
...........
};
error:function(){
.......
};
});
3.继续说错误,看返回参数是否符合你的要求(dataType不要写错,如dateType,datatype);
4.在检查后台,
1).是否有@ResponseBody响应体;
2).检查xml中是否配置:<mvc:annotation-driven>,默认创建注解处理器映射器,注解处理器适配器。提供json格式支持。
3).检查jar包:
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.4.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.4.6</version>
</dependency>
4.返回参数是否键值对形式,以map集合为例:
Map<String, String> map=new HashMap<String, String>();
map.put("key1", "value1");