[mod_python] Mod_python and Ajax

Nicolas Lehuen nicolas.lehuen at gmail.com
Sat Oct 8 17:03:09 EDT 2005


Hi Lee,

If you want to play with AJAX at a low level, well, it's easily done in
mod_python.

AJAX really needs a framework on the client, to wrap things like how to
build a XMLHttpRequest object in a portable manner, handle the asynchronous
callbacks, work around browser bugs and Javascript limitations, etc.

But the server side doesn't need to change ; for instance, if you're doing
partial page updates by replacing HTML fragments (using
getElementById("foobar").innerHTML = whatever_the_server_sent_me;), then you
keep on writing the same code as before on the server side, but now some of
your code will only return fragments of pages instead of full pages each
time. I mean, you can directly use the "Hello world" test handler from the
mod_python tutorial and use it with some AJAX client code !

If you want to push things a little further (but then you're not low-level
anymore), you may want to exchange only data between the client and the
server, and do the formatting on the client side. To do this, you could send
XML from the server (using the same techniques as before) and use the
obnoxious DOM API on the client side to process and format the data. Or,
there is a popular alternative right now which uses JSON (JavaScript Object
Notation, IIRC), which is a serialisation of basic data types in a way that
can just be eval()ed in Javascript. There are Python libraries to serialise
its core data types (tuples, lists, dicts) in JSON, it could be interesting
to integrate them with mod_python to make things easier. But then again,
it's only a matter of putting glue at the right spot, nothing really
difficult.

There are many, many things that can be imagined on the server-side when
taking into account the new AJAX fad, but at a low level, only the
client-side requires a framework.

Regards,
Nicolas

2005/10/8, Lee Brown <administrator at leebrown.org>:
>
> Greetings!
>
> I've become interested in playing around with Ajax; one, just so I'll know
> what all the buzz is about and two, with mature client-side code available
> like MochiKit and Richo it looks like a cool and painless way to really
> spiff up an xml-driven web site.
>
> I know there are full-blown frameworks out there like Myghty that are
> based on AJAX, but I'd like to piddle around with it at a lower level to see
> how well it plays with mod_python. Has anyone out there played around with
> it? Has anyone seen a simple little test handler I could muck about with?
>
> Best Regards,
> Lee E. Brown
> (leebrown at leebrown.org)
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20051008/89400994/attachment.html


More information about the Mod_python mailing list