Though its pretty simple and has been there for a long time now, I am writing this post to help new users.
Check the code below with three links. We will use these links to call our data using ajax calls.
To make an ajax call using JQuery with actionURL
To make an ajax call using JQuery with resourceURL
To make an ajax call using AlloyUI and resourceURL
Hope this helps someone in need.
You can get the source of the portlet here on github
Ajax JQuery Portlet
This portlet is for 6.1.20 version of Liferay and for previous versions you can check here.
Ajax JQuery Portlet
Until next time. Keep Ajax -ing :-)
Check the code below with three links. We will use these links to call our data using ajax calls.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="mainCanvas"> | |
<a href="#" id="dataLink" class="linkBtn">Get User Data using ActionUrl</a> | |
<span id="userData"></span> | |
<hr /> | |
</div> | |
<div id="mainCanvas2"> | |
<a href="#" id="dataLink2" class="linkBtn">Get User Data using ResourceURL and ServeResource</a> | |
<span id="userData2"></span> | |
<hr /> | |
</div> | |
<div id="mainCanvas3"> | |
<a href="#" id="dataLink3" class="linkBtn">Get User Data using ResourceURL and ServeResource Alloy UI</a> | |
<span id="userData3"></span> | |
<hr /> | |
</div> |
To make an ajax call using JQuery with actionURL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#dataLink").click(function(){ | |
var url = '<portlet:actionURL windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>"><portlet:param name="ajaxAction" value="getData"></portlet:param></portlet:actionURL>'; | |
$.post(url, {}, function(data){ | |
$("#userData").html(data); | |
}) | |
}); |
To make an ajax call using JQuery with resourceURL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#dataLink2").click(function(){ | |
var url = '<portlet:resourceURL id="getDataResourceURL"></portlet:resourceURL>'; | |
$.post(url, {username:'ravi'}, function(data){ | |
$("#userData2").html(data); | |
}) | |
}); |
To make an ajax call using AlloyUI and resourceURL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#dataLink3").click(function(){ | |
var url = '<portlet:resourceURL id="getDataAUIResourceURL"></portlet:resourceURL>'; | |
AUI().use( | |
'aui-io-request', | |
function (Y) { | |
Y.io.request( | |
url, | |
{ | |
on: { | |
success: function() { | |
var data = this.get('responseData'); | |
$("#userData3").html(data); | |
} | |
} | |
} | |
); | |
} | |
); | |
}); |
Hope this helps someone in need.
You can get the source of the portlet here on github
Ajax JQuery Portlet
This portlet is for 6.1.20 version of Liferay and for previous versions you can check here.
Ajax JQuery Portlet
Until next time. Keep Ajax -ing :-)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.