blog | bio | agenda | jobs | ajaxCFC

AjaxCFC for jQuery Alpha Release

I finished today the implementation of AjaxCFC for jQuery. It's the same Ajax <-> CF integration you already know, but using the jQuery Ajax engine. It supports full JSON and WDDX serialization, has improved error handling, improved log4javascript integration, still supports named and unnamed arguments, and just so you can use it right away, it's back compatible with the DWR syntax. The only incompatibility is the change of the $() function, which you can actually override if you wish, but I didn't on my release.

This is great news folks, because jQuery is extensible and allows for easily dropping plugins into your code...
I will work in documenting it for beta release, but those of you who wish to use the bleeding edge version just add a comment and I'll send you the code. I'd appreciate comments and suggestions from those who wish to check it out.

Public Beta release should come sometime next week.

Related Blog Entries

TrackBacks
jQuery & ColdFusion: AJAX for ColdFusion
Rob & I have been using jQuery for awhile now and even thrown out the possibility of making a version of AjaxCFC that uses jQuery under the hood. Well, Rob went off and actually did it!!! Today, Rob officially announced the AjaxCFC for jQuery Alpha Release.
Tracked by Rey Bango's Blog | Tracked on 12/27/06 3:33 PM
If you needed another reason to use jQuery, it’s here
Lucky I did because the end all reason to use jQuery in Coldfusion was released today as Rob Gonda announced the Ajax CFC for jQuery Alpha Release earlier today. I’ve liked everything I’ve seen of AjaxCFC, especially since there is quite a bit of support for Model Glue around the AjaxCFC community as well. Looks like this will knock out the last straw holding me to using Prototype.
Tracked by Adam on Life | Tracked on 12/28/06 6:37 AM

Trackback URL for this entry:
http://www.robgonda.com/blog/trackback.cfm?C51A8D88-3048-7431-E4369541ED335DC5

Comments
Rob,

Awesome! You know I want it!
# Posted By Sami Hoda | 12/27/06 2:46 PM
Awesome news Rob. I'll try to give you feedback ASAP.
# Posted By Rey Bango | 12/27/06 3:34 PM
So my question is, why would I use AxaxCFC if jQUery already has Ajax support built in? Is it simply that AjaxCFC is made for CF?

ps. I'm not being belligerent...just wondering.
# Posted By Andy Matthews | 12/27/06 3:40 PM
Andy,

The significance of this is that you should now be able to directly call a function inside a cfc from your jQuery code (i'd give you a sample, but I haven't gotten the chance to play with it just yet). Before using jQuery, you had to call a cfm page that either did the processing for you and returned a result (probably using JSON), or you called a cfm page that in turn called the CFC that you already wrote to handle whatever problem it was, and the return is handled for you. You simply use <CFReturn ...>

I just got the alpha release an hour or so ago, and haven't had the chance to play with it, but I'm assuming that this is how it works. Please Rob (or anybody really), correct me if I'm wong here. :o)
# Posted By Christopher Jordan | 12/27/06 3:59 PM
... um... hang on. My post didn't make much sense. Sorry Andy.

Before, you had two options.
1) no CFC at all, just call a CFM page from your jQuery code and return your result via the savecontent tag. In many cases where I was wanting to return a query, an array, or a structure I had to run my output through CFJson before outputting it with the savecontent tag.

2) use the CFC that you already wrote to solve whatever problem it is. Except because you can't directly call a CFC from within jQuery's $.ajax() method (well, you could, but the result would be returned to you wrapped in a WDDX packet, and you'd have to deal with that on your own... yuck!). So instead, you call a CFM page that then calls the CFC and then the CFM page takes the value or object (array, struct, query, etc.) that was returned by the CFC and packages it -- again probably using CFJson (really a very cool UDF, CFJson is) -- and use cfsavecontent again to get it back to your jQuery code.

Now, though we should be able to call our CFC methods directly, and all the WDDX and such should be handled for us! (Thank you Rob!) It also sounds like he's made several more improvements. This is what I've been waiting for. When I switched to jQuery, I was a bit sad at leaving ajaxCFC behind. I'm really glad to see the two come together! :o)

Well, I hope that clears up my previous post which was... uh... Rob can you just delete that last post of mine? It really makes no sense. :o/

Hope that helps, Andy! :o)

Cheers,
Chris
# Posted By Christopher Jordan | 12/27/06 4:08 PM
Andy, you may use jQuery directly, just like you could use prototype, Dojo, Spry, YUI, or even a plain XHR request... but using AjaxCFC facilitates a few issues you would encounter if you don't: like Chris said, it takes care of serialization when sending and receiving from the server, in fact, jQuery does not automatically serialize complex values for you. I build json and wddx support, and I will try to add plain JS structures to improve efficiency for beta. AjaxCFC also provides error handling, debugging thru log4javascript integration, and most importantly, if guides you to use proper design patterns such as facade and/or a centric lightweight controller.

Like Chris said, you may invoke your CFCs directly, but 1) they will return wddx/xml, and 2) you would have to expose all your methods as remote. AjaxCFC forces you to create an Ajax Facade, which interacts with your presentation layer (Ajax calls) and your business model (CFCs). Large applications will have a clearly defined business model, persist your service layer using a sort of object factory (coldspring), and make the Ajax Facade as light and dumb as possible, simply passing requests to your service layer, and allowing AjaxCFC to send the result back to the calling page.

So in summary, AjaxCFC is nothing but a library that facilitates your day-to-day development, taking advantage to robust proven libraries such as DWR and jQuery, and guide you to use proper design patterns when developing your application.

HTH
# Posted By Rob Gonda | 12/27/06 4:48 PM
Awesome news, Rob. I was really hoping you'd come-up with this... and here it is. Thanks. Looking forward to your AjaxCFC+jQuery.
# Posted By Michael E. Carluen | 12/28/06 12:07 AM
This is a great development. I'd really appreciate if you sent it to me.

One question. I've gotten some strange behavior when trying to bring in both Spry and JQuery. Do both framework play well together, or are there any issues you are aware of?

Thanks!

Doug Ward
# Posted By Doug Ward | 12/29/06 12:11 PM
I use both jQuery and AjaxCFC daily, so I would love to get my hands on the code!
# Posted By Thomas D. | 12/31/06 4:46 PM
Would love to try out the new code, looking forward to it.
# Posted By Sean Dearnaley | 1/1/07 8:04 PM
I'd love to check it out.
# Posted By Mike Tumbarello | 1/3/07 9:50 AM
Rob,

Happy New Year and thanks for your continued service to our community.
I just discovered jQuery and have used CF since 2.0 - would love to test AjaxCFC/jQuery.
Continued success.
Dean Glasener
# Posted By Dean Glasener | 1/4/07 9:46 AM
I use jQuery alot and would love to try out AjaxCFC
# Posted By Gabe Roffman | 1/4/07 3:35 PM
Yes,
I'd like to get a copy. I've just started to use jQuery, and this sounds perfect for a project I had in mind. Keep up the good work!

Paul.
# Posted By Paul | 1/6/07 9:26 AM
Rob,

I'd like a go at the MachII or ModelGlue segments when they are ready for testing..
# Posted By Dan Wilson | 1/8/07 4:44 PM
I'm trying to use the current version of AjaxCFC and the current release of jQuery together on the same page.

I'm getting the following error...

disabledZone.style has no properties

(no name)()
util.js (line 259)
_sendData(Object map=Object paramCount=0 ids=[1] preHooks=[1]) engine.js (line 407)
endBatch(undefined) engine.js (line 183)
_execute("/com/myCFC.cfc", null, "getSomething", undefined) engine.js (line 390)
myCoolLookup() (line 95)
onblur(blur ) (line 1)
[Break on this error] disabledZone.style.visibility = 'visible';



Is this the $() error you were talking about Rob? If so, how do I override it?

This is for a live site, so any feedback would be appreciated.

- Thomas
# Posted By Thomas D. | 1/9/07 7:21 PM
Thomas, that is correct... there's a conflict with the $() function.
Rey gave a solution here http://tech.groups.yahoo.com/group/ajaxcfc/message...
However, if you would like to keep the $() from jQuery and not use the one from DWR, all you have to do is look for instances of the $() in the utils.js file and rename it to something else... it's all self-contained in there, so you won't really break anything by renaming it.
# Posted By Rob Gonda | 1/9/07 10:47 PM
Sorry for the delay of sending the code to some of you. I will probably post the Alpha 2 release into the SVN this weekend.
Dan, the Model-Glue and Mach-ii version will come along with the beta release.
Thank you all for your support.
# Posted By Rob Gonda | 1/10/07 11:42 PM
Thomas...

Actually, jQuery has addressed this by allowing you to call jQuery methods using jQuery() instead of $(). They added this in because many people were using jQuery with Prototype.

So this:
$('#myID').remove()
is the same as this:
jQuery('#myID').remove()
# Posted By Andy Matthews | 1/11/07 1:33 PM
Andy, 'jQuery' is actually the original/proper namespace. It will always work, and plugins should use it instead of the aliases or abbreviations. The $() is nothing but a pointer to the jQuery namespace with the sole purpose of simplifying or shortening its use.
# Posted By Rob Gonda | 1/11/07 8:19 PM
The alpha 2 code is now available thru SVN. More information here: http://www.robgonda.com/blog/index.cfm/2007/1/15/A...
# Posted By Rob Gonda | 1/15/07 1:24 AM
Hi Rob, this looks great - i'm looking forward to the final release. FYI: the plugins link has changed to http://docs.jquery.com/Plugins.
# Posted By nick tong | 2/13/07 2:53 AM
Updated
# Posted By Rob Gonda | 2/13/07 9:31 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.1.004.