[nycphp-talk] JSON and MVC
Chris Snyder
chsnyder at gmail.com
Wed Jul 15 11:49:28 EDT 2009
On Wed, Jul 15, 2009 at 10:31 AM, Hans Zaunere<lists at zaunere.com> wrote:
> The Javascript then takes each element from the array and manipulates the
> DOM as appropriate. Why not just stuff things in innerHTML you may ask?
> Because that's not granular enough, and should the user be interactive with
> that particular element, the user has just lost his current state.
Maybe you need a javascript template system? That way you would only
be passing data in JSON, and then coercing that into a template on the
client side. Template may == DOM-building-function if that's more
suitable than string replacement and innerHTML stuffing.
In other words, if the client knows how to add events to a calendar
(using DOM), then you can just send a stream of event details using
JSON. Very lightweight on the server side, and you're not mixing
markup and data anymore.
As a bonus, that approach sets you up for thinking in terms of a local
database, which leads to offline functionality.
More information about the talk
mailing list