[英]Resolving view from ajax request using spring 3
Jquery code to call my spring controller: Jquery 代码调用我的 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 find it all works fine until the return string(view name), what am I doing wrong?然后我的 controller 代码导致
http 500 error
,我已经调试它并发现它一切正常,直到返回字符串(视图名称),我做错了什么?
@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;在 controller 上使用 jquery 加载和 get 请求在一定程度上起作用 - 因为它返回视图并加载到对话框中; but the attribute is not added to model and I can not post json data to the controller.
但该属性未添加到 model 并且我无法将 json 数据发布到 controller。
Any tips?有小费吗?
Have you tried putting @ResponseBody in your Controller?您是否尝试过将@ResponseBody 放入您的 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
有关此注释的更多信息在这里: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-ann-responsebody
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.