Calling a Coldfusion Function with CFAJAX

CFAJAX allows you to call, via Javascript, CF functions you have defined in a CF file which will run server-side and return info to the page. In CFAJAX 1.2, the call syntax changed a little from previous versions; the basic format is:

DWREngine._execute(_cfscriptLocation, null, 'SomeCFFunctionHere', Argument1, Argument2......., resultHandler);

In the above line:

* _cfscriptLocation is the web location of ColdFusion file that contains the CF functions you wish to call. This location is usually set in the CFAJAX file settings.js. It can be absolute from the web root (e.g. /cfajax/core/settings.js) or a full http://... URL (it can also be relative to the calling page but that will just cause hassles when you create pages in other locations).

* null - pass this in every cfajax call and leave it as null.

* 'SomeCFFunctionHere' is the name of the CF Function you want to call inside your functions file.

* Argument1, Argument2... are the arguments you want to pass to the CF function. Make sure you get the order right.

* resultHandler is the JS function in your page that will handle the return result when CFAJAX comes back to the page.

So, for example, If my CF Function was:

<cffunction name="AddOne" returntype="numeric">
<cfargument name="InputNumber" required="yes" type="numeric">
<cfreturn ARGUMENTS.InputNumber + 1>
</cffunction>

I'd call it like this:

var myNumber = 23; DWREngine._execute(_cfscriptLocation, null, 'AddOne', myNumber, resultHandler);

and I'd get 24 as a return

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
dhaval parekh's Gravatar I am trying to use CJAJAX on a form. It works great, but in IE the callback function doesn't get called. So it does make a remote call, but when its done it doesnt call the callback function. In firefox it works perfectly.

Did you encouter this as well?
# Posted By dhaval parekh | 8/30/06 5:41 PM
James Holmes's Gravatar Your best bet is to join the CFAJAX mailing list on Yahoo Groups and post some code there.

http://groups.yahoo.com/group/cfajax/
# Posted By James Holmes | 8/30/06 9:50 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.5.1.