Jahia Dev Forum > How to create a...

0 (0 Good)
0 (0 Bad)

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

by  rali »  2013/08/26 12:26

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 = '${url.base}${currentNode.path}.sqlPaging.do';
  $.post(location, function(data) {
    $('#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

  (rali)

Number of messages  8
Registration date
2 (2 Good)
0 (0 Bad)

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

by  qlamerand »  2013/08/26 12:54

Hello Rasheed,
You need to specify the expected data type in your jQuery post.
You will have something like :

 

var location = '${url.base}${currentNode.path}.sqlPaging.do';
  $.post(location, null, function(data) {
    $('#result').html(data.info);
 }, "json");
 
Here is the jQuery documention for the post function : http://api.jquery.com/jQuery.post/
 
Regards,
Quentin
  • Re: How to create a Jahia Ajax Call (JSP,JQuery)
    2017/04/21 14:14

    qlamerand <p> Hello Rasheed,<br /> You need to specify the expected data type in your jQuery post.<br /> You will have something like :</p> <p> &nbsp;</p> <div> var location = &#39;${url.base}${currentNode.path}.sqlPaging.do&#39;;</div> <div> &nbsp; $.post(location, null, function(data) {</div> <div> &nbsp; &nbsp; $(&#39;#result&#39;).html(data.info);</div> <div> &nbsp;}, &quot;json&quot;);</div> <div> &nbsp;</div> <div> Here is the jQuery documention for the post function :&nbsp;<a href="http://api.jquery.com/jQuery.post/">http://api.jquery.com/jQuery.post/</a></div> <div> &nbsp;</div> <div> Regards,</div> <div> Quentin</div>

  • Number of messages  28
    Registration date Aug 26, 2013
    0 (0 Good)
    0 (0 Bad)

    Answered!

    by  rali »  2013/08/26 15:10

    Thank You, 

     

    That was the problem. I needed to have JSON in the Ajax call and I needed to call data.info.

     

    THanks qlamerand 

      (rali)

    Number of messages  8
    Registration date
    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