Personal tools
You are here: Home Blog Archive 2008 February 24 Mason AJAX
Document Actions

Mason AJAX

Filed Under:
We've been updating our webpages to become more "2.0". The GrokThis.net webpage now has keyword-based navigation, and the VPS Village pages are entirely AJAX-enabled. Quite simply, we're using Scriptalicious and Prototype for most of it. There is very little new backend code. Its quite simply a matter of removing the templates from the code. Out backend layout something like:
comp_root/
|
|- autohandler - site template
|- subdir/ - subdirectory
|
|- autohandler
|- index.html
|- index_plain.html
Assume comp_root/autohandler contains:
 <html><body>
<h1>GrokThis</h1>
<% $m->call_next %>
<div id="footer">Copyright notice</div>
</body></html>
Then comp_root/subdir/autohandler contains:
 <h2>Sub-Directory content</h2>
<div id="content">
<% $m->call_next %>
</div>
Now, if comp_root/subdir/index.html contains:
 <h1>hello world</h1>
Loading http://example.net/subdir/ will render:

GrokThis

Sub-Directory content

hello world

Now, here is the AJAX rub... we create index_plain.html which contains:
 <!-- Might want to add %ARGS here, or modify arguments as needed -->
<& index.html &>
<%flags>
inherit=>undef
</%flags>
When you load http://example.net/subdir/index_plain.html, you will see simply:

hello world

We will now copy the subdir directory to subdir2: cp -R subdir subdir2 Then, modify subdir2/index.html:
 <p>this is the subdir2 directory!</p>
All one needs to do then, is modify comp_root/autohandler:
 <html>
<head><script language="javascript" src="prototype.js"></script></head>
<body>
<script>
function update(contentvar, dirvar) {
new Ajax.Updater(contentvar, dirvar, { method: 'get' });
}
</script>
<h1>GrokThis</h1>
<a href="/subdir" onclick="update('content','/subdir1'); return false;">
Sub-Dir #1
</a>
<a href="/subdir1" onclick="update('content','/subdir1'); return false;">
Sub-Dir #2
</a>
<% $m->call_next %>
<div id="footer">Copyright notice</div>
</body></html>
The content div will now update automatically, and it will fail-over for older browsers! Mason's idea of components really works well with the AJAX concept and there are all kinds of things you can do with it, and in much prettier ways than this. This example is meant to be short and easy... and very important, simple for retrofitting an existing site. Have fun, and take care!
Syndication
Tag cloud
upgrade vps xen howto rails django ajax virtualization security mason software
Log in


Forgot your password?
New user?
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: