Jahia in English > Use json object...

0 (0 Good)
0 (0 Bad)

Use json object from ActionResult...

by  kissenlall »  2013/03/03 13:26

 

Hi.

I am currently returning a json object in my action result from an action. this redirects to a jsp page. I want to be able to access the json object returned from the action in this jsp page.

How to achieve that?

Many Thanks

Kissenlall

  • Use json object from ActionResult...
    2013/03/03 13:26

    kissenlall <p> &nbsp;</p> <p style="margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 20px;"> Hi.</p> <p style="margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 20px;"> I am currently returning a json object in my action result from an action. this redirects to a jsp page. I want to be able to access the json object returned from the action in this jsp page.</p> <p style="margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 20px;"> How to achieve that?</p> <p style="margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 20px;"> Many Thanks</p> <p style="margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 20px;"> Kissenlall</p>

  • Number of messages  7
    Registration date Mar 3, 2013
    0 (0 Good)
    0 (0 Bad)

    Re: Use json object from ActionResult...

    by  shuber »  2013/03/04 13:12

    Hello,

    Best way to do that is to use an AJAX request to call your action and then the JSON response becomes accessible through the AJAX response.

    Best regards,

      Serge Huber.

    Serge Huber (shuber)

    Number of messages  271
    Registration date
    0 (0 Good)
    0 (0 Bad)

    Need help implementing the advice of JSon into Ajax call from ActionResult

    by  rali »  2013/08/26 12:31

    Hello, 

     

    I am trying to do this same thing and the Json is not coming through. 

    I've added code detial here. 

     

    Ultimately :

     

    JAVA.CLASS

    .....
    json.put("iTotalDisplayRecords", totalRows);
    ActionResult result = new ActionResult(HttpServletResponse.SC_OK, null, json);
    result.setJson(json);
    return result;
     
    JSP PAGE
    $.post(${url.base}${currentNode.path}.javaAction.do, function(data) {$('#result').html(data);alert(data);});
     
     
    Can you please help me?
  • Need help implementing the advice of JSon into Ajax call from ActionResult
    2013/08/26 12:31

    rali <p> Hello,&nbsp;</p> <p> &nbsp;</p> <p> I am trying to do this same thing and the Json is not coming through.&nbsp;</p> <p> <a href="https://www.jahia.com/home/download/forum/jahia-developer/jahia-dev-forum/how-to-create-a-jahia-ajax-call.html">I&#39;ve added code detial here.&nbsp;</a></p> <p> &nbsp;</p> <p> Ultimately :</p> <p> &nbsp;</p> <p> <strong>JAVA.CLASS</strong></p> <div> .....</div> <div> json.put(&quot;iTotalDisplayRecords&quot;, totalRows);<span class="Apple-tab-span" style="white-space:pre"> </span></div> <div> ActionResult result = new ActionResult(HttpServletResponse.SC_OK, null, json);</div> <div> result.setJson(json);</div> <div> return result;</div> <div> &nbsp;</div> <div> <strong>JSP PAGE</strong></div> <div> $.post(${url.base}${currentNode.path}.javaAction.do, function(data) {$(&#39;#result&#39;).html(data);alert(data);});</div> <div> &nbsp;</div> <div> &nbsp;</div> <div> Can you please help me?</div>

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

    answered

    by  rali »  2013/08/26 15:13

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

    $.post(${url.base}${currentNode.path}.javaAction.do, function(data) {$('#result').html(data.info);alert(data.info);},"json");

    THanks qlamerand

  • answered
    2013/08/26 15:13

    rali <p style="margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 20px;"> That was the problem. I needed to have JSON (in quotes) in the Ajax call and I needed to call &quot;data.info&quot;.</p> <p style="margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 20px;"> $.post(${url.base}${currentNode.path}.javaAction.do, function(data) {$(&#39;#result&#39;).html(data<strong>.info</strong>);alert(data<strong>.info</strong>);}<strong>,&quot;json&quot;</strong>);</p> <p style="margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14.44444465637207px; line-height: 20px;"> THanks&nbsp;<strong><a href="https://www.jahia.com/en/users/gh/ai/jc/qlamerand.forum-profile.html?jsite=7d813234-6e72-412b-a534-45c73b7fb75f" style="color: rgb(102, 153, 0); text-decoration: none; outline: 0px;">qlamerand</a></strong></p>

  • Number of messages  8
    Registration date Aug 26, 2013
    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