@Dirk: Thanks for pointing that out! This indeed solves my trouble
with creating complex HTML in JavaScript (jQuery to be precise). The
code ends up being very clean and easy to read. Great!
@Aditya: The shortcomings for AJAX-heavy web apps that you pointed out
are absolutely valid. In my case, SEO is not an important factor as
users have to sign in to use the app anyway. As for the browser, yes
people will need a JavaScript. In the days of Gmail most people should
have been turned into JavaScript fans anyway ;)
Rendering HTML on the server and loading it via AJAX requests does not
automatically make your site look like in the 90's. In fact for my
question, the resulting web page should look exactly the same for JSON
and server HTML versions.
Here is a screenshot of the app I'm working on:
http://startupsignals.com/wp-content/uploads/2010/11/ajax-ui-example.jpg
It's similar to an RSS reader with a master-detail interface. When a
user clicks on a review from the list in the top part, the details are
fetched via AJAX and the lower right content pane is filled.
In my case I decided to generate the HTML on the server with a
template. Loading it on click is 2 lines of jQuery:
var detailsAction = #{jsAction @Ajax.activityDetails(':id') /}
$('#activity-details').load(detailsAction( { id: $
(this).attr('id') } ) ); // Load server generated HTML
Everything you see in the lower right corner of the screenshot is
generated on the server and pulled in dynamically.
I'm quite happy with the readability/maintainability of the code. The
template as well as the JavaScript look clean. The price is a higher
load on the server, but in my case I hope to get away with that.
-Rico