Friday, June 12, 2009

AJAX under the hood a bit more

In my second attempt to use ajax techniques in a new application, my first through was
1 - it needs to work in all major browsers
2 - i need to put my code that is speaking to the DB in the model, and call it as a function and deal with the results in the view page.

For me, a natural progression. In my first implementation, i did not really use javascript to render the result of my asychonous call - i just output the result of the view page to a html div. This was ok for initial success, but it needs to work across IE and FF and i would like to keep presentation code separated from server code and let javascript be the one who is rendering the result set.

This is a little more difficult. I am spoiled by cold fusion and its query construct, which makes it very easy to get a resultset and output it in a html page.

Initially, i did a search for cold fusion ajax and tutorials and found alot of stuff, including, no big surprise here, a AJAX framework for cold Fusion. Rob Gonda created ajaxCFC in 2006. There is also a framework called MxAJAX and CFAjax. I also found a google group for MXAjax. Needless to say, there is alot to get your head around.

Some of the things im realizing is that at some point, you have to bit the bullet (so to speak) and roll up your sleeves and get into javascript and how it works with queries and other complex data types (structs and arrays). This is really what we need to master to become proficient at ajaxing. The frameworks and tags and other helper apps, utils that are available are really masking the need to learn how javascript works natively on complex data types.

I found this comment that summed up this point well.

"At some point you're going to have to accept that there
is no client side ColdFusion. The "J" in AJAX is JavaScript. If you're
going to be working with AJAX, you're going to have to bite the bullet at
some point and roll up your sleeves and work with JavaScript. Or, yes, you
can use the built in AJAX functionality within CF. depending on what you
need to do it might be robust enough. But (IMO) the built in AJAX stuff,
while handy for quick one-offs, is not a replacement for really knowing and
understanding how to work with AJAX.
"

I am learning about JSON (java script object notation) and JQuery (a javascript library of functions), each seems to be an important concept to grok regarding ajaxing.

I am currently trying to use the ajaxCFC framework, since it works with components and is recommended by enough CFers. It has a light footprint (this is lingo that means its not a real big framework in terms of number of files). and requires the developer to include a couple javascript files and a coldfusion cfc, that is then extended by cfcs that are being called using the framework.

Look at the next post for specifics regarding ajaxCFC.

No comments:

Post a Comment