I’ve taken a little break from tech postings here because most of my tech postings of late had been about Flock, and I wanted to group those elsewhere. Here’s another tech posting that’s relevant to Flock because I wrote this code for a project for Flock, but it doesn’t exactly belong at that blog because it’s not specifically about Flock. So feel free to skip over this one, dear family members.
- Write php functions to do server-side data manipulation and to use xajax calls to manipulate the page upon request return.
That’s it. Arguments passed to the js function are passed straight through to the php function, and you have to do no special mumbo jumbo to make the thing work. The out-of-the-box functionality is pretty simple when compared to the libraries available at, for example, script.aculo.us, but xajax is reportedly extensible, so you’re certainly not limited to what you get out of the box.
Now, on to why this is ideal for Drupal development. The more I use Drupal, the more appealing I find its API. It’s pretty simple to extend the software. For example, I recently wanted to add a little snippet of code next to the title of any sort of node. Lucky for me, the Drupal developers thought to include a nodeapi hook, which lets you do just what I wanted to do. For all its niceness in some areas, though, it’s painful to do some things in Drupal. Adding global ajax support seemed a likely candidate for such pain because Drupal’s got menu hooks, a permissions system, etc., that I thought might make for tedious hacking.
- Install and enable xajax.module.
- For the module you’re writing, define MODULE_xajax_init and include function registration calls.
- Within your module, define the php functions you’ve registered.
That’s it. Voila. Magic, easy ajax support in Drupal.