【问题标题】:How to create a Jahia Ajax Call (JSP,JQuery)如何创建 Jahia Ajax 调用 (JSP,JQuery)
【发布时间】:2013-08-28 21:50:25
【问题描述】:

当我构建一个模块/组件时,我需要将什么传递给 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

【问题讨论】:

    标签: java jsp jquery wcm


    【解决方案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

    【讨论】:

      【解决方案2】:

      另一个处理 ajax 调用的解决方案是注册你自己的 spring mvc 控制器。 Jahia Web 应用预装了 spring core、spring beans、spring aop 以及您可能需要的一切。

      您需要在 application-context.xml 文件中进行一些配置。

      您甚至可以通过注释 ex.@Controller 使用并成为老板,而不是在 xml 文件中注册 jahia 控制器。

      http://fruzenshtein.com/spring-mvc-ajax-jquery/

      干杯!

      【讨论】:

      • 这看起来很有趣!我得试试。
      猜你喜欢
      • 1970-01-01
      • 2018-02-02
      • 2010-11-27
      • 1970-01-01
      • 2014-08-17
      • 1970-01-01
      • 1970-01-01
      • 2015-08-15
      • 1970-01-01
      相关资源
      最近更新 更多