拔掉我的头发。无数小时试图让ajax调用工作......
查询:
function doAjaxPost(episode_id) {
alert("cc");
$.ajax({
type: "POST",
url: "http://localhost:8080/yay/episodes/remove",
data: JSON.stringify({
episode_id : episode_id
}),
dataType: 'json',
contentType: "application/json",
success: function(){
alert("o");
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.error(errorThrown);
}
});
};
控制器:
@RequestMapping(value = "/episodes/remove", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void removeEpisodeFromList(@RequestBody String episode_id) {
System.out.println("Episode_id : " + episode_id);
}
我从以下位置调用函数:
<a href = "#" onclick = "doAjaxPost(${episode.episode_pk});"> MARK AS WATCHED </a>
它到达控制器,打印出正确的东西。但随后 FireBug 只是说“SyntaxError {}”并且永远不会调用成功函数警报。