1.前台
$.ajax({
method:'post',
data:jsonStr,
url:'xxxxx/good',
contentType: "application/json; charset=utf-8",
dataType: "json",
success:function(result){
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
}
});
2.springmvc
@ResponseBody
@RequestMapping(value={"good",""})
public String savetobt(@RequestBody String jsonStr){
List<BigDelay> list=JsonUtil.fromJson(jsonStr, List.class);
return "";
}
3.出现问题
ajax请求springmvc成功后仍然执行error模块,分别弹出200, 4,parsererror
3.问题原因
springmvc返回的结果不是json类型的数据
4.解决办法:改返回类型
@ResponseBody
@RequestMapping(value={"good",""})
public String savetobt(@RequestBody String jsonStr){
List<BigDelay> list=JsonUtil.fromJson(jsonStr, List.class);
System.out.println(list);
String jsonResult=JsonUtil.toJson("");
return jsonResult;
}