My Jump Into AJAX
In the last few weeks I’ve been toying a bit with AJAX in some simple demo ColdFusion apps – pretty much just testing the waters. For anyone who, like me, has been slow to adopt AJAX, it’s time to jump in. I’ll try and post some of my little samples for anyone who might be thinking of trying it out sometime soon. In the mean time, here was my experience…
I decided to try the two most popular (in the usergroups and forums anyway) AJAX components out there: CFAjax and AjaxCFC. I read up a bit on both of them and there’s no one out there that’s really dismissing either – most people agreeing that they each have their pros and cons.
For no good reason whatsoever, I tried CFAjax first. It was very easy to install and the setup instructions were very straightforward. I got it all set, ran a test to make sure it was working, and life was good. I spent about an hour trying to get my own AJAX application to work on top of it, and I honestly couldn’t. Maybe I had missed a step, or maybe I was overlooking the obvious somewhere, but it just wasn’t happening. I decided to move on and try the next one, coming back to this if I needed to later.
AjaxCFC was a whole different story. Setup was a breeze (not that CFAjax wasn’t, they both were very easy), and I immediately got a new test application working – first try! After getting a pretty basic function working that would just accept text I entered, manipulate it in some way and pipe it back out, I wanted to test out some queries. This proved just a smidge more difficult. At no fault of AjaxCFC, I couldn’t figure out how to manipulate the query data once it was returned from the server. After reading up (it’s been a while!) on my javascript, I got it going.
For anyone who runs into this as their first snag, you reference your query as follows:
1 | returnvar.column_name[row_number] |
For example:
1 | r.country_name[2] |
Now obviously you can plop your variables in there and have a dynamic AJAX application running in no time! Kudos Rob Gonda for AjaxCFC.
