سؤال

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

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

Another solution to handle ajax calls is to register your own spring mvc controller. Jahia web app comes pre-loaded with spring core, spring beans, spring aop and everything you might need.

You will need to do some configuration in the application-context.xml file.

You can even use and and be a boss with annotaions ex.@Controller, instead of registering jahia controllers in xml files.

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

Cheers !

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top