I make an ajax request using jquery, this calls the following spring controller:
@RequestMapping(value = \"/dialogController\", method = RequestMethod.POST)
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 model
parameter from controller method. I also then realized I had to also return a new model and view; here is the working code:
var myJSON = {"title":"help"};
myJSON = JSON.stringify(myJSON);
<c:url var="postAndView" value="/PostJSONMAV" />
...
jQuery.ajax({
type: 'POST',
url: "${postAndView}",
data:myJSON,
contentType: "application/json",
success: function(data) {
previewDialog.html(data);
previewDialog.dialog('open');
}
});
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:
@RequestMapping(value = "/PostJSONMAV", method = RequestMethod.POST)
public ModelAndView postJSON(@RequestBody MyClass myClass) {
ModelAndView mav = new ModelAndView();
myClass.setTitle("SUCCESS");
mav.setViewName("dialogContent");
mav.addObject("myClass", myClass);
return mav;
}