春季 JSON 请求获取 406(不可接受)
2022-08-31 11:47:55
这是我的javascript:
function getWeather() {
$.getJSON('getTemperature/' + $('.data option:selected').val(), null, function(data) {
alert('Success');
});
}
这是我的控制器:
@RequestMapping(value="/getTemperature/{id}", headers="Accept=*/*", method = RequestMethod.GET)
@ResponseBody
public Weather getTemparature(@PathVariable("id") Integer id){
Weather weather = weatherService.getCurrentWeather(id);
return weather;
}
弹簧服务.xml
<context:annotation-config />
<tx:annotation-driven />
收到此错误:
GET http://localhost:8080/web/getTemperature/2 406 (Not Acceptable)
头:
响应标头
Server Apache-Coyote/1.1
Content-Type text/html;charset=utf-8
Content-Length 1070
Date Sun, 18 Sep 2011 17:00:35 GMT
请求标头
Host localhost:8080
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2
Accept application/json, text/javascript, */*; q=0.01
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection keep-alive
X-Requested-With XMLHttpRequest
Referer http://localhost:8080/web/weather
Cookie JSESSIONID=7D27FAC18050ED84B58DAFB0A51CB7E4
有趣的说明:
我收到406错误,但休眠查询同时工作。这是tomcat日志所说的,每次当我在Dropbox中更改选择时:
select weather0_.ID as ID0_0_, weather0_.CITY_ID as CITY2_0_0_, weather0_.DATE as DATE0_0_, weather0_.TEMP as TEMP0_0_ from WEATHER weather0_ where weather0_.ID=?
问题可能出在哪里?之前在SO中有两个类似的问题,我在那里尝试了所有被接受的提示,但我想它们不起作用......
有什么建议吗?随时提问...