【发布时间】:2017-11-12 06:43:06
【问题描述】:
我正在尝试将 JSON 数组发送到位于 gamesetting.jsp 上的 fullCalendar。 json 数组对象已通过控制台进行了测试,并且
它显示了正确的答案。然后我尝试了 $("#calendar").fullCalendar( 'addEventSource', source ),chrome 返回 406 错误并希望响应为The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.
@RequestMapping ( method=RequestMethod.GET ,produces={"application/json; charset=UTF-8"})
public @ResponseBody JSONObject returnGames(GameVO gameVo,HttpServletResponse response) throws IOException{
GameService gService= new GameService(gameDao);
List<GameVO> games= gService.select(gameVo);
JSONArray jsonArray = new JSONArray();
JSONObject jsonObj =null;
for(GameVO game:games){
jsonObj = new JSONObject();
jsonObj.put("game_no", game.getGame_sd());
jsonObj.put("game_name", game.getGame_name());
jsonObj.put("game_time", game.getGame_time());
jsonArray.put(jsonObj);
}
System.out.println("jsonArray: "+jsonArray);
response.setHeader("Accept", "application/json");
return jsonObj;
}
显示在控制台中
jsonArray: [{"game_name":"A vs B","game_time":"2015-05-20 00:00:00.0","game_no":1}]
这是我的 JavaScript 代码
$(document).ready(function() {
$('#calendar').fullCalendar({
customButtons: {
myCustomButton: {
text: 'custom!',
click: function getGames(e){
var games;
var url='selectAllGames.controller';
if (getGames){
$.getJSON(url,null,
function(){$("#calendar").fullCalendar( 'addEventSource',url )})
;}
console.log(e);
}
}
},
我真的不知道出了什么问题......
【问题讨论】:
-
删除此行时会发生什么
response.setHeader("Accept", "application/json"); -
@Sagar Rohankar - 响应标头将没有接受属性,并且仍然返回具有相同描述的 406 错误。
标签: javascript arrays json spring fullcalendar