print Tutorial 3: Adding Ajax controls to a controller

Introduction to xaJax

The Scorpio Framework integrates xaJax into the controller layer to handle ajax requests. Alternatives to this approach include using the output type control to send back XML, XHTML or JSON to jQuery, Prototype etc (this is actually used for the tag editor) and is more useful where complex responses are required or if additional processing must be performed on the client side.

xaJax is very effective though for quick ajax functionality, form submission, browsing search results etc. and can be integrated very easily. It is used extensively in the admin system for many of the control applets.

By default, xaJax is not active in the base controller. This is to avoid loading the files if they are not used. At the time of writing, version 0.5 RC1 is currently being distributed, though this will be upgraded to the latest release shortly.

The main difference (in my mind) between xaJax and other approaches is that xaJax is very much focused on modifying the web page, not just returning data. This is seen in the "assign" method where you can target specific elements and manipulate them from the PHP side. This does tightly couple the view to the controller and this is why ajax requests are handled separately - it is more a bonus than a requirement; but as ajax is a web technology this is a useful way of approaching it. If you need to be able to make available the data via other mechanisms, then the output type is the method to use instead of xajax.

This tutorial will add a very basic random comment in place of the comment list on the Guestbook tutorial. This will use some of the basic features.

So what do we need to do to get ajax working?