I've encountered an issue while making an ajax post call to my Spring controller. The data is successfully saved in the database, but I'm seeing a 404 error on the browser console when the POST request is made. Additionally, once the call returns from the controller, the error function of the ajax call is triggered.
Could someone please point out what might be missing here?
$('#submitMessage').submit(function(e){
e.preventDefault();
var formData = {};
var msg=document.getElementById('iconLeft4-1');
var url = "${context}/wasadmin/support/ajax/send";
formData['comment']=msg.value;
formData['commented_by']='1';
formData['supportId']='1';
formData['userType']='O';
console.log(JSON.stringify(formData));
$.ajax({
type : 'POST',
contentType: "application/json",
url : url,
dataType : 'json',
data:JSON.stringify(formData),
success:function(data,status,xhr){
console.log('saved successfully');
},
error:function(data,status,xhr){
console.log('error occured'); // This gets printed
}
});
Controller
@PostMapping(value="/ajax/send")
public void sendSupportMessage(@RequestBody SupportConversationDTO supportConversationDTO) {
supportConversationService.save(supportConversationDTO);
return;
}