
« Back to Web Content...
AJAX Loaded Articles
Table of Contents [-]
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.
28601 Views