我有一个AJAX
来电,应该返回JSON
文件
function getData() {
$.ajax({
url: '/x',
type: 'GET',
data: "json",
success: function (data) {
// code omitted
}
});
}
我的服务器端很简单。
@RequestMapping(value = "/x", method = GET, produces = "application/json")
public @ResponseBody List<Employee> get() {
return employeeService.getEmployees();
}
但我的要求甚至无法进入控制器。错误是:
HTTP Status 415 - The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.
我该如何解决?
答案 0 :(得分:0)
在服务器端代码
之前添加@Consumes("text/html")
@Consumes("text/html")
@RequestMapping(value = "/x", method = GET, produces = "application/json")
public @ResponseBody List<Employee> get() {
return employeeService.getEmployees();
}