Jahia DX > How to create a...

0 (0 Good)
0 (0 Bad)

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

by  koparki »  2014/08/19 12:30

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

 

  • How to create a Jahia Ajax Call (JSP,JQuery)
    2014/08/19 12:31

    koparki <p>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?</p> <p>For instance (in my <a href="http://www.maszynybudowlane24h.pl/">.</a>jsp):</p> <pre class="lang-java prettyprint prettyprinted" style=""> <code><span class="pln">var location </span><span class="pun">=</span><span class="pln"> </span><span class="str">&#39;${currentNode.path}.sqlPaging.do&#39;</span><span class="pun">;</span><span class="pln"> $</span><span class="pun">.</span><span class="pln">post</span><span class="pun">(</span><span class="pln">location</span><span class="pun">,</span><span class="pln"> function</span><span class="pun">(</span><span class="pln">data</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> temp</span><span class="pun">=</span><span class="pln">data</span><span class="pun">;</span><span class="pln"> alert</span><span class="pun">(</span><span class="pln">data</span><span class="pun">.</span><span class="pln">info</span><span class="pun">);</span><span class="pln"> $</span><span class="pun">(</span><span class="str">&#39;#result&#39;</span><span class="pun">).</span><span class="pln">html</span><span class="pun">(</span><span class="pln">data</span><span class="pun">);</span><span class="pln"> </span><span class="pun">});</span></code></pre> <p>Further Information (here is my Class):</p> <pre class="lang-java prettyprint prettyprinted" style=""> <code><span class="lit">@Override</span><span class="pln"> </span><span class="kwd">public</span><span class="pln"> </span><span class="typ">ActionResult</span><span class="pln"> doExecute</span><span class="pun">(</span><span class="typ">HttpServletRequest</span><span class="pln"> req</span><span class="pun">,</span><span class="pln"> </span><span class="typ">RenderContext</span><span class="pln"> renderContext</span><span class="pun">,</span><span class="pln"> </span><span class="typ">Resource</span><span class="pln"> resource</span><span class="pun">,</span><span class="pln"> </span><span class="typ">JCRSessionWrapper</span><span class="pln"> session</span><span class="pun">,</span><span class="pln"> </span><span class="typ">Map</span><span class="pun">&lt;</span><span class="typ">String</span><span class="pun">,</span><span class="pln"> </span><span class="typ">List</span><span class="pun">&lt;</span><span class="typ">String</span><span class="pun">&gt;&gt;</span><span class="pln"> parameters</span><span class="pun">,</span><span class="pln"> </span><span class="typ">URLResolver</span><span class="pln"> urlResolver</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">throws</span><span class="pln"> </span><span class="typ">Exception</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="typ">JSONObject</span><span class="pln"> json </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">JSONObject</span><span class="pun">();</span><span class="pln"> json</span><span class="pun">.</span><span class="pln">put</span><span class="pun">(</span><span class="str">&quot;info&quot;</span><span class="pun">,</span><span class="lit">3.14</span><span class="pun">);</span><span class="pln"> </span><span class="typ">ActionResult</span><span class="pln"> result </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">ActionResult</span><span class="pun">(</span><span class="typ">HttpServletResponse</span><span class="pun">.</span><span class="pln">SC_OK</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">null</span><span class="pun">,</span><span class="pln"> json</span><span class="pun">);</span><span class="pln"> result</span><span class="pun">.</span><span class="pln">setJson</span><span class="pun">(</span><span class="pln">json</span><span class="pun">);</span><span class="pln"> </span><span class="kwd">return</span><span class="pln"> result</span><span class="pun">;</span><span class="pln"> </span><span class="pun">}</span></code></pre> <p>Packages used: javax.servlet.http org.jahia.bin.ActionResult org.json.JSONObject</p> <p>&nbsp;</p>

  • Number of messages  1
    Registration date Aug 19, 2014
    Contact
    Share
    Feedback

    Get in touch

    Whether you are a current user or if you are just evaluating Jahia, we are here to help.

    Contact us

    Share this page