I'm trying to implement a very basic AJAX call in my Spring application (Never used AJAX before). For now I'm just trying to make a call that returns a string, and updates a text area in a form. I know the JQuery code is getting invoked no issues as I can debug the sending part in my browser, and the controller is getting the request. I thought the @ResponseBody annotation was somehow supposed to magically return just the contents of the method return value but its like JQuery doesn't "see" it or something. The controller simply returns the string back and the entire html page just shows the string. I cannot hit the SUCCESS portion in debug in the JQuery call. Am I missing something here?
Form (truncated for readability)
<form id="ajaxTaskUpdate" th:action="@{/updateTask}" th:object="${Task}" method="post">
<textarea id="taskDescription" name="taskDescription" class="materialize-textarea blue" th:text="${task.description}" maxlength="250"></textarea>
</form>
Jquery snippet
$('#ajaxTaskUpdate').submit(function(event) {
$.ajax({
url : $("#ajaxTaskUpdate").attr("action"),
data : data,
type : "POST",
success : function(response) {
//BREAKPOINT NEVER HITS HERE
$("#taskDescription").text(response);
},
error : function(xhr, status, error) {
alert(xhr.responseText);
}
});
return false;
});
Spring Controller
@RequestMapping(value = "/updateTask", produces = "application/json", method = RequestMethod.POST)
@ResponseBody
public String updateTask(Task task) {
//I want this to be "ajaxed" into my form's text area
return "successful Ajax Response!";
}
GUI after Controller response
