On Tue, Dec 15, 2009 at 2:44 PM, tjones <[email protected]> wrote: > Hello, > I have done this the conventional way for some time now and I now have > a few minutes to start looking in to using AJAX. Are there any good > how-to's on using cfajaxproxy? For a start I would like to have a drop > down "cfselect" which displays a different set of records on each > selection. > > Sorry for the delay in getting back to you.
Basics are here: http://wiki.openbluedragon.org/wiki/index.php/CFAJAXPROXY How this works at a high level is you use cfajaxproxy to create a proxy to your CFC that can be used from javascript. Then you can handle the select box data pulls and repopulation all in javascript, but using data pulled from your CFC. Simple example--assume you have a CFC called Foo.cfc and it has the following function: <cffunction name="sayHello" access="remote" output="false" returntype="string"> <cfreturn "Hello!" /> </cffunction> Then on a CFML page you can do the following: <cfajaxproxy cfc="Foo" jsclassname="Foo" /> <script type="text/javascript"> var foo = new Foo(); foo.setCallbackFunction(bar); foo.sayHello(); function bar(message) { alert(message); } </script> Very simple example but a couple of things to point out. First, make sure the cffunctions in your CFC that you want to access from javascript have their access level set to remote. Second, the callback function bit in the javascript is the best way to handle the interaction between javascript and the CFC. So when you call the method, when the response is returned that will call the javascript function you have set as the callback function. This is important due to the asynchronous nature of these requests--if, for example, you did this in the javascript: var foo = new Foo(); var message = foo.sayHello(); alert(message); The problem is that the alert line doesn't wait to make sure the previous line completed since it's an asynchronous request. So the callback function is pretty critical. Hope that gets you going. -- Matthew Woodward [email protected] http://mpwoodward.posterous.com identi.ca/Twitter: @mpwoodward Please do not send me proprietary file formats such as Word, PowerPoint, etc. as attachments. http://www.gnu.org/philosophy/no-word-attachments.html -- Open BlueDragon Public Mailing List http://www.openbluedragon.org/ http://twitter.com/OpenBlueDragon mailing list - http://groups.google.com/group/openbd?hl=en !! save a network - please trim replies before posting !!
