Pulling out my hair. Countless hours trying to get ajax call to work...
Jquery:
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);
}
});
};
Controller:
@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);
}
And I call the function from:
<a href = "#" onclick = "doAjaxPost(${episode.episode_pk});"> MARK AS WATCHED </a>
It reaches the controller where the correct thing is printed out. But then FireBug just says "SyntaxError {}" and success function alert is never called.