开发者

Resolving view from ajax request using spring 3

开发者 https://www.devze.com 2023-03-27 02:15 出处:网络
Jquery code to call my spring controller: $.postJSON(\"/DialogController\", myJSON, function(data) { previewDialog.html(data);

Jquery code to call my spring controller:

$.postJSON("/DialogController", myJSON, function(data) {
  previewDialog.html(data);
  previewDialog.dialog('open');
});

And then my controller code, which causes a http 500 error, I have debugged it and fin开发者_Python百科d it all works fine until the return string(view name), what am I doing wrong ?

@RequestMapping(value = "/DialogController", method = RequestMethod.POST)
public String dialogController(Model model, @RequestBody MyClass myClass) {
  myClass.setTitle("SUCCESS");       
  model.addAttribute("myClass", myClass);
  return "dialogContent";
}

Using jquery load with get request on the controller works to an extent - in that it returns the view and loads into dialog; but the attribute is not added to model and I can not post json data to the controller.

Any tips ?


Have you tried putting @ResponseBody in your Controller? More information on this annotation is here: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-ann-responsebody

0

精彩评论

暂无评论...
验证码 换一张
取 消