我正在寻找在spring mvc
中获得ajax成功后返回值列表@RequestMapping(value = "/getAlertNotification.ftl")
public ModelAndView getAlertNotification(HttpServletRequest request
){
Map<Object, Object> model = new HashMap<Object, Object>();
User user = RequestUtils.getUser(request);
List<CardRequestNotification> Cardreqlist=cardRequestManager.cardRequestNotification(user);
model.put("listObj", Cardreqlist);
return new ModelAndView(new JSONView(model));
}
$("#alertLink").click(function()
{ var $this = j$(this);
GtsJQuery.ajax(GtsJQuery.getContextPath()
+ "/getAlertNotification.ftl",
function(data) {
/* how i return Cardreqlist object list`enter code here` in here */
});
答案 0 :(得分:1)
我猜你有一个误解概念,如果你想要返回一个ModelAndView然后你需要指定将要渲染的JSP文件或html模板,你需要特定的ModelAndView名称。
但是你正在混合使用Views和JSON,这是用于AJAX调用的,所以我猜你的代码会更像这样:
@RequestMapping(value = "/getAlertNotification.ftl")
@ResponseBody
public List<CardRequestNotification> getAlertNotification(HttpServletRequest request
){
Map<Object, Object> model = new HashMap<Object, Object>();
User user = RequestUtils.getUser(request);
List<CardRequestNotification> Cardreqlist=cardRequestManager.cardRequestNotification(user);
model.put("listObj", Cardreqlist);
return Cardreqlist;
}
然后在你的JS代码中你可以做到:
data.Cardreqlist