« Back to Web Content...

AJAX Loaded Articles

Introduction #

This describes a way to dynamically load content articles based upon a certain URL Parameter passed to a single page.

Explanation #

Given a URL:

http://www.myurl.com/mypage?id=34523&gid=10136

First a little Javascript can be used to parse out the id url parameter. This functon is taken from http://www.netlobo.com/url_query_string_javascript.html:

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

Next, this function uses AJAX to grab the contents of the article:

function grabArticle(articleId, groupId) {
    jQuery.ajax({
        url: "/c/journal/view_article_content?groupId=" + groupId + "&articleId=" + articleId + "&version=1.0&p_p_state=exclusive",
        success: function(data) {
            jQuery('#content').html(data);
        }
    });
}

Lastly, the grabArticle function is run onDocumentReady:

jQuery(document).ready(function() {
    var eid = gup('id');
    var groupId = gup('gid');
    grabArticle(eid, groupId);
});

All of this Javascript can be placed in a JS file that is dynamically loaded into a Velocity template theme.

0 Attachments
28601 Views
Average (3 Votes)
The average rating is 2.6666666666666665 stars out of 5.
Comments
Threaded Replies Author Date
For more on Liferay ... Rohit Salecha May 9, 2011 11:52 PM
For more on Liferay ... Rohit Salecha May 9, 2011 11:58 PM
For more on Liferay ... Rohit Salecha May 9, 2011 11:59 PM

For more on Liferay

http://liferaydemystified.blogspot.com/
Posted on 5/9/11 11:52 PM.
For more on Liferay

http://liferaydemystified.blogspot.com/
Posted on 5/9/11 11:58 PM.
For more on Liferay

http://liferaydemystified.blogspot.com/
Posted on 5/9/11 11:59 PM.