0

I'm having issues setting up an ajax call in Liferay. In my View.jsp, I have:

<portlet:actionURL name="action" var="action" />

AUI().ready(function(A) {
    A.use('.button').on('click',function(){
        A.io.request('${action}', {
               method: 'POST',
               data: {
                 key1: 'value'
               },
               on: {
                   success: function() {
                       debugger;
                     alert(this.get('responseData'));
                   }
               }
            });
    });   
});

and in my Portlet.java, I have:

public void action(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException {
        System.out.println("hello world");
}

The result is that an ajax call is being made, and it is hitting my action, but then its proceeding to hit the view.jsp that I'm currently on. Is there a way to tell liferay to hit a different jsp file?

ContextSwitch
  • 2,830
  • 6
  • 35
  • 51

1 Answers1

1

It looks like i needed to use serveResource instead of an action, since actions appear to always render the page.

Liferay ajax request and JSON response

ContextSwitch
  • 2,830
  • 6
  • 35
  • 51
  • [**respond to http request with json object in portlet**](https://stackoverflow.com/questions/17592144/respond-to-http-request-with-json-object-in-portlet) – Parkash Kumar Jun 23 '17 at 12:06