Skip to content

Instantly share code, notes, and snippets.

@psvehla
Created October 4, 2012 00:04
Show Gist options
  • Save psvehla/3830682 to your computer and use it in GitHub Desktop.
Save psvehla/3830682 to your computer and use it in GitHub Desktop.
Liferay article API snippet
<%@ 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(/\&amp;/g, '&').replace(/\&lt;/g, '<').replace(/\&gt;/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>
@psvehla
Copy link
Author

psvehla commented Jan 17, 2015

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