Ajax Example with Django, Prototype and MochiKit |
||||||
This Ajax example has been written in 2006 and therefore it is slowly falling behind the technology curve. A good deal of html interaction could be done more elegantly with jquery. That is the javascript library that I would use today (May 2008) to implement the same functionality. Note 2: Make sure to read the security notice at the end of this page. The following is an AJAX demo developed as a means of learning about this technology. There are two versions of the demo with different javascript libraries Prototype and MochiKit. The target use case was the so called in-place-editing, creating and submitting a form without leaving the page.
AJAX calls are made for both populating and saving the text area, feedback messages are displayed while the data is being fetched and saved. In a nutshell the approach works by assigning IDs for all the HTML tags (DOM elements) that need to be interacted with. As you'll see there are quite a few to keep track of. But once one forms a picture of what needs to be displayed at which stage, it simply becomes a matter of creating, removing hiding or showing these elements. Files to look at:
As far as this demo goes the most notable difference seems to be in the way HTML elements are generated. The prototype based approach pieces the DOM elements toghether from strings, while mochikit can generate them with functions ... (it might just also be that I was unable to discover some functionality in prototype). The MochiKit approach resulted in cleaner code ... on the other hand I did it second and by that time I already had a good sense of what I was trying to do. I'll probably be using this latter though, one of its quite unique features (not shown here) is a logging capability that turns out to be a great timesaver. Get the full source here: ajax-sandbox.zip To run the demo you'll need to have django present. You may need to edit the run.bat or run.sh script files so that the django module appears in the python path. Send feedback, comments or corrections to istvan.albert@gmail.com , cheers. ---- SECURITY NOTICE ----Luke Plant has recently sent me the following email On this page:
|
||||||
| <<back |