Ahmed Aswani
Ahmed Aswani

Reputation: 8649

Liferay: Call JSON service from portlet

I'm trying to call a json web service with my portlet javascript code: In the js/main.js i have:

   Liferay.Service(
  '/Basic-portlet.hello/remote-hello',
  {
    name: ''
  },
  function(obj) {
    console.log(obj);
  }
);

this call executes only once when I add the portlet to the page, whenever page reloaded a javascript error raised:

Uncaught TypeError: undefined is not a function
A.mix.parseIOConfig
A.mix.parseInvokeArgs
Service    main.js?browserId=other&lan....
(anonymous function)

Upvotes: 1

Views: 1021

Answers (2)

Jesse Rao
Jesse Rao

Reputation: 146

I've seen this happen when you try to invoke a Liferay JSON web service from a context without access to AlloyUI.

Add the following AUI import:

<script src="http://cdn.alloyui.com/2.0.0/aui/aui-min.js"></script>

Then wrap your service invocation like this:

AUI().use('aui-base', function(A){
  // Liferay Service invocation here
});

E.g.,

AUI().use('aui-base', function(A){
  Liferay.Service(
    '/user/get-user-by-email-address',
    {
      companyId: Liferay.ThemeDisplay.getCompanyId(),
      emailAddress: '[email protected]'
    },
    function(obj) {
      console.log(obj);
    }
  );
});

Upvotes: 3

Gaurav
Gaurav

Reputation: 72

I have faced similar issues in past. Try disabling the javascript minifier and see if that solves your issue. It fixed my issue.

Thanks, Gaurav

Upvotes: 1

Related Questions