Created
October 4, 2012 00:04
-
-
Save psvehla/3830682 to your computer and use it in GitHub Desktop.
Liferay article API snippet
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
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> | |
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %> | |
<script type="text/javascript" src="/html/js/liferay/service.js"> </script> | |
<script type="text/javascript"> | |
function unEscapeHTML(html) { | |
return html.replace(/\&/g, '&').replace(/\</g, '<').replace(/\>/g, '>'); | |
} | |
function getJournalArticle(articleId, target) { | |
$.ajax({ | |
type: 'GET', | |
url: "/api/jsonws/journalarticle/get-article?groupId=10180&articleId=" + articleId, | |
dataType: "json", | |
success: function(data, textStatus, jqXHR) { | |
$(target).html(unEscapeHTML(data.content)); | |
}, | |
error: function(jqXHR, textStatus, errorThrown) { | |
alert("Error calling count service: " + textStatus + " : " + errorThrown); | |
} | |
}); | |
} | |
// we will add our javascript code here | |
$(document).ready(function() { | |
// do stuff when DOM is ready | |
getJournalArticle(12601, 'div.dynamic-content'); | |
getJournalArticle(12611, "#on-demand-content"); | |
$("#on-demand-content").hide(); | |
$("#details").click(function() { | |
if($("#details").text() == 'More Details') { | |
$("#details").text('Less Details'); | |
$("#on-demand-content").show(); | |
} | |
else { | |
$("#details").text('More Details'); | |
$("#on-demand-content").hide(); | |
} | |
}); | |
}); | |
</script> | |
<p> | |
<h1>Liferay Content</h1> | |
<h2>Server Gets Content</h2> | |
<liferay-ui:journal-article groupId="10180" articleId="11001" /> | |
<h2>Client Gets Content</h2> | |
<div class='dynamic-content'></div> | |
<h2>Client Gets Content When Needed</h2> | |
<a id='details'>More Details</a> | |
<div id='on-demand-content'></div> | |
</p> | |
<p>The time on the server is ${serverTime}.</p> |
If you're having cross-domain issues, then look at CORS and JSONP.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great. Thank you Man. I need to use it on my website, but I'm security problem the site is on another server, you know how can I give permission?