I have a button in a HTML page with JQuery 1.8. I'm using Spring MVC 4.1 to handle the requests.
var test= "foo";
$.ajax({
type : "POST",
async : false,
url : "rest/ping",
data : JSON.stringify(test),
dataType : "json" ,
contentType : "application/json",
error : function(jqXHR, textStatus, errorThrown) {
alert(errorThrown + " -- " + jqXHR.responseText);
},
success : function(data) {
console.log("bar");
}
});
The Spring side:
@Controller
@RequestMapping("/test")
public class DummyController {
@RequestMapping(value = "/rest/ping", method = RequestMethod.POST)
@ResponseBody
public void ping(@RequestBody String test) throws ServiceException{
// nothing of concern
}
}
If I remove the @ResponseBody the system cannot find the mapping. If I add '(required=false)' to the request body annotation then the mapping is found but the ajax call fails because after the mapped url is called, the system calls "test/rest/ping/rest/ping".
If you have a documentation of JQuery and Spring MVC working together, please add them to this question. I'm not able to find a valid example describing exact this strange behaviour. If you have any questions, please ask. Thank you all for your time.