« 返回到 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 附件
28608 查看
平均 (3 票)
满分为 5,平均得分为 2.6666666666666665。
评论
讨论主题回复 作者 日期
For more on Liferay ... Rohit Salecha 2011年5月9日 下午11:52
For more on Liferay ... Rohit Salecha 2011年5月9日 下午11:58
For more on Liferay ... Rohit Salecha 2011年5月9日 下午11:59

For more on Liferay

http://liferaydemystified.blogspot.com/
在 11-5-9 下午11:52 发帖。
For more on Liferay

http://liferaydemystified.blogspot.com/
在 11-5-9 下午11:58 发帖。
For more on Liferay

http://liferaydemystified.blogspot.com/
在 11-5-9 下午11:59 发帖。