« Zurück zu 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 Anhänge
28607 Angesehen
Durchschnitt (3 Stimmen)
Die durchschnittliche Bewertung ist 2.6666666666666665 von max. 5 Sternen.
Kommentare
Antworten im Thread Autor Datum
For more on Liferay ... Rohit Salecha 9. Mai 2011 23:52
For more on Liferay ... Rohit Salecha 9. Mai 2011 23:58
For more on Liferay ... Rohit Salecha 9. Mai 2011 23:59

For more on Liferay

http://liferaydemystified.blogspot.com/
Gepostet am 09.05.11 23:52.
For more on Liferay

http://liferaydemystified.blogspot.com/
Gepostet am 09.05.11 23:58.
For more on Liferay

http://liferaydemystified.blogspot.com/
Gepostet am 09.05.11 23:59.