这是我的javascript:
function getWeather() {
$.getJSON('getTemperature/' + $('.data option:selected').val(), null, function(data) {
alert('Success');
});
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
@RequestMapping(value="/getTemperature/{id}", headers="Accept=*/*", method = RequestMethod.GET)
@ResponseBody
public Weather getTemparature(@PathVariable("id") Integer id){
Weather weather = weatherService.getCurrentWeather(id);
return weather;
}
Run Code Online (Sandbox Code Playgroud)
为spring-servlet.xml
<context:annotation-config />
<tx:annotation-driven />
Run Code Online (Sandbox Code Playgroud)
得到此错误:
GET http://localhost:8080/web/getTemperature/2 406 (Not Acceptable)
Run Code Online (Sandbox Code Playgroud)
头:
响应标题
Server Apache-Coyote/1.1
Content-Type text/html;charset=utf-8
Content-Length 1070
Date Sun, 18 Sep 2011 17:00:35 GMT
Run Code Online (Sandbox Code Playgroud)
请求标题
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, …Run Code Online (Sandbox Code Playgroud) 我在SO中看到了很多复杂的问题,不管某些复杂的结构是否被认为是有效的JSON.
但是在光谱的另一端呢?
"12345"
Run Code Online (Sandbox Code Playgroud)
以上是有效的JSON吗?