javajspjquerywcm

How to create a Jahia Ajax Call (JSP,JQuery)


When I build a module/component what do I need to pass to the ActionResult in order to recieve the proper HTTPServletRequest in an Ajax call?

For instance (in my jsp):

var location = '${currentNode.path}.sqlPaging.do';
  $.post(location, function(data) {
    temp=data;
    alert(data.info);
    $('#result').html(data);
 });

Further Information (here is my Class):

@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;

    }

Packages used: javax.servlet.http org.jahia.bin.ActionResult org.json.JSONObject


Solution

  • That was the problem. I needed to have JSON (in quotes) in the Ajax call and I needed to call "data.info".

    var location = '${currentNode.path}.sqlPaging.do';
      $.post(location, function(data) {
        temp=data;
        alert(data.info);
        $('#result').html(data);
    },"json");
    

    THanks qlamerand