|
Software Architecture |
||||
|
|
||||
| Ajax Architecture | ||||
AJAX proponents prefer this mechanism over going to the server for new pages. It can be combined with a RestfulArchitecture to make server side services usable from any client, including the address bar of any browser.
The downside is a ton of JavaScript, which we have learned is hard to debug, trace, standardize, etc. It also has performance and cross-browser compatibility issues. Whew.
01 <html>
02 <head>
03 <title>Ajax Demo</title>
04 <%= javascript_include_tag "prototype" %>
05 </head>
06 <body>
07 <h1>What time is it?</h1>
08 <div id="time_div">
09 I don't have the time, but
10 <%= link_to_remote( "click here",
11 :update => "time_div",
12 :url =>{ :action => :say_when }) %>
13 and I will look it up.
14 </div>
15 </body>
16 </html>
In line 10 LinkToRemote is a ROR function. Link means it is rendered as a
regular anchor tag link. The URL argument in line 12 tells it to call the "say_when"
function on the server, and line 11 tells it to update (replace) the contents of
the "time_div" section. See why OnLamp
calls it Ajax on Rails!