我试图通过jsp中的AJAX调用从spring控制器获取JSON响应。 下面是代码。
Spring MVC Controller:
@RequestMapping(value = "/data.htm", method = RequestMethod.GET, headers="Accept=*/*",consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public TestVO testMe(){
TestVO testVO = manageService.getData(2);
return testVO ; //I am getting testVo but after returning from here I am getting 406 Not Acceptable issue
}
JSP中的Ajax调用:
$.ajax({
url: url2,
type: "GET",
beforeSend: function(xhr) {
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
},
success: function(smartphone) {alert("hi");
}
});
请建议解决方案。
此致