Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
major major
Load a web content using Ajax
September 9, 2013 2:49 AM
Answer

major major

Rank: New Member

Posts: 13

Join Date: November 1, 2012

Recent Posts

I'm using Liferay 6.06.
When I click a button in a page I need to show a div which is populated dynamically with a web content.
I want to load this web content using ajax.
How this can be done?
Pankaj Kathiriya
RE: Load a web content using Ajax
September 9, 2013 4:01 AM
Answer

Pankaj Kathiriya

Rank: Liferay Master

Posts: 632

Join Date: August 4, 2010

Recent Posts

You can get content in form of String by below code if you have articleId with you.

1String content=JournalArticleLocalServiceUtil.getArticleContent(themeDisplay.getScopeGroupId(),articleId,null,themeDisplay.getLanguageId(),themeDisplay)


Make use of serveResource method to use ajax.
Write below code in serveResouce method
1String content=JournalArticleLocalServiceUtil.getArticleContent(themeDisplay.getScopeGroupId(),articleId,null,themeDisplay.getLanguageId(),themeDisplay)
2resourceResponse.getWriter().write(content);


You can get it this content in ajax call in success function as a data.
For example if you are using jquery for ajax then below code would be helpful
 1
 2    jQuery.ajax({
 3            url:'<portlet:resourceURL>
 4    <portlet:param name="articleId" value="3"></portlet:param>
 5</portlet:resourceURL>',
 6            success:function(response){
 7                jQuery("#articleContentBox").html(response);
 8                 }
 9});


HTH,
Pankaj K | CIGNEX Datamatics