Adam Perfect

Making things easier

I started using 'AJAX' methods a while ago, playing with it to see what it could do and then actually using it for a client project where their customers needed to be able to submit any number of service requests at once. The traditional way of doing this would be to either leave the customer with the hard work and just let them submit one at a time until they're done, or to provide an input where they can declare how many requests they wish to make this time and the page will reload with the given number of forms. With a bit of this new-fangled AJAX stuff sprinkled on top, we now have one form to mae one request at a time, but rather than waiting for the page to reload, it simply keeps a running tab of the requests you've made so far in a new div under the form. This was a pretty nifty addition and it got used in a couple of areas on the site, though it wasn't done in the cleanest way. The javascript for the actions all got mixed in with the HTML (onsubmit="" and all that) which of course somewhat flies in the face of accessible, standards-based design where content, presentation and function are all separated out. And thus I eventually found Behaviour by Ben Nolan. It's a single .js file you add in your head area and then create another file with an associative array of functions to apply to various elements in your page, linked by CSS selectors. This pulls the javascript trickery out of the main body of code and generally makes things simpler, more re-usable and maintainable. So check it out. Aside from the above revalation, I also finally got round to looking at more than just the combination demos of script.aculo.us. I knew the Prototype library that script.aculo.us builds on had some handy ready-made AJAX functions but with the complete lack of documentation on the Prototype site and my inate laziness, I never found out what they were. Well, turns out the script.aculo.us wiki has some documentation to cover Prototype! As a result, I can stop re-inventing the wheel for simple AJAX calls and use Ajax.Request or Ajax.Updater. The Ajax.InPlaceEditor is also very handy and gives you nice flickr-style editing of elements where they sit in the page, via either a normal input or textarea.

Written by Adam on

You may also like…