I make an ajax request using jquery, this calls the following spring controller:
@RequestMapping(value = "/dialogController", method = RequestMethod.POST)
public String dialogController(Model model, @RequestBody MyClass myclass) {
myClass.setTitle("SUCCESS");
model.addAttribute("myClass",myClass);
return "dialogContent"; //this resolves to dialogContent.jsp
}
However I receive the following error :
org.springframework.web.HttpRequestMethodNotSupportedException:
Request method 'POST' not supported
And if required here is the ajax call I am making using jQuery:
jq.postJSON("/dialogController", myClass, function(data) {
myDialog.html(data);
myDialog.dialog('open');
//dialog settings previously assigned,
//but the success callback function is not reached anyway
});
EDIT
I get same error if I use :
jq.ajax({
type: 'POST',
url: "/dialogController",
data:myClass,
success: function(data) {
previewDialog.html(data);
previewDialog.dialog('open');
});
For the viewers at home … I found that the problem was due to the method signature defined in controller not matching the ajax call. I removed the
Model modelparameter from controller method. I also then realized I had to also return a new model and view; here is the working code:I changed to the ajax call but
jQuery.postJSON()will probably work aswell. And shown below is the new controller code, which corrrectly adds a new object to model and returns jsp page, which is opened up in a dialog: