Entries published on August 5, 2006
Django tips: A simple AJAX example, part 2
Last time around we looked at how to write a simple view which processes a form and either returns errors or returns success, and then tweaked it slightly so that the same view could handle either a “regular” form submission (in which case it operates normally), or an XMLHttpRequest
(in which case it returns JSON).
Today we’ll look at writing the JavaScript side of it; for reference, here’s the live example we’re going to build. This will be a fairly long write-up, but that’s not an indication of the complexity of the process; I’m deliberately being much more verbose than necessary in order to cover a few important points about good JavaScript style and conventions.
All of the JavaScript we’re going to write in this article goes into a single file which, along with the necessary files from the YUI toolkit, will be pulled in by the example.
Choice of toolkit
There …