当我构建模块/组件时,我需要传递给ActionResult才能在Ajax调用中接收正确的HTTPServletRequest?
例如(在我的jsp中):
var location = '${currentNode.path}.sqlPaging.do';
$.post(location, function(data) {
temp=data;
alert(data.info);
$('#result').html(data);
});
更多信息(这是我的班级):
@Override
public ActionResult doExecute(HttpServletRequest req, RenderContext renderContext, Resource resource,
JCRSessionWrapper session, Map<String, List<String>> parameters, URLResolver urlResolver)
throws Exception {
JSONObject json = new JSONObject();
json.put("info",3.14);
ActionResult result = new ActionResult(HttpServletResponse.SC_OK, null, json);
result.setJson(json);
return result;
}
使用的套餐: javax.servlet.http包 org.jahia.bin.ActionResult org.json.JSONObject
答案 0 :(得分:1)
这就是问题所在。我需要在Ajax调用中使用JSON(引号),我需要调用“data.info”。
var location = '${currentNode.path}.sqlPaging.do';
$.post(location, function(data) {
temp=data;
alert(data.info);
$('#result').html(data);
},"json");
感谢qlamerand
答案 1 :(得分:1)
处理ajax调用的另一个解决方案是注册自己的spring mvc控制器。 Jahia网络应用程序预装了弹簧芯,弹簧豆,弹簧和您可能需要的一切。
您需要在application-context.xml文件中进行一些配置。
你甚至可以使用和成为一个带有注释的老板@Controller,而不是在xml文件中注册jahia控制器。
http://fruzenshtein.com/spring-mvc-ajax-jquery/
干杯!