Skip to content

Instantly share code, notes, and snippets.

@jamesfalkner
Created November 15, 2013 20:22
Show Gist options
  • Save jamesfalkner/7490954 to your computer and use it in GitHub Desktop.
Save jamesfalkner/7490954 to your computer and use it in GitHub Desktop.
## AJAXification with well-formed JSON result construction and parameter passing
## Calling a Liferay JSON Web Service
#set ($pns = $request.portlet-namespace)
<body onload="${pns}doit()">
<p><em>Demo 7: Using Liferay JavaScript APIs</em></p>
<img src="http://www.liferay.com/osb-community-theme/images/custom/heading.png">
<div id="greeting"></div>
<div id="rawdata"></div>
<script type="text/javascript">
function ${pns}doit() {
Liferay.Service(
'/user/get-user-by-screen-name',
{
companyId: '$getterUtil.getLong($companyId)',
screenName: 'test'
},
function (user) {
document.getElementById('greeting').innerHTML =
'<h3>' + user.greeting + '</h3>';
document.getElementById('rawdata').innerHTML =
'<pre>' + JSON.stringify(user) + '</pre>';
}, function (err) {
console.log("uh oh!");
}
);
}
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment