Oh yeah, and of course include the path to jquery.AjaxCFC.js in your HTML:
<script type="text/javascript"
src="../js/ajaxCFC/jquery.AjaxCFC.js"></script>
- Jack
Jack Killpatrick wrote:
Hi Gareth,
Here are the basics:
1. add ajaxCFC to your CF project (or somewhere that it can get to).
2. create a CFC that extends AJAXCFC.ajax:
<cfcomponent extends="AJAXCFC.ajax">
<!--- security stuff --->
<cfscript>
setAllowedVerbs('POST');
setCheckHTTPReferer(true);
</cfscript>
<cffunction name="myFunction" output="no" access="private">
do some CF stuff
<cfreturn something />
</cffunction>
</cfcomponent>
For the cfreturn, you can return queries, structs, pretty much any cf
object (see the docs for any limitations, I've had good success having
cfreturn return structs, arrays of structs, queries, etc).
AJAXCFC.ajax will handle converting the "something" that you are
returning to the requested format (see #3):
3. Add config info to your js file/script (see docs for full set of
config options):
$.AjaxCFCHelper.setDebug(false);
$.AjaxCFCHelper.setUseDefaultErrorHandler(false);
$.AjaxCFCHelper.setSerialization('json'); // json, wddx
4. call the remote CFC:
$.AjaxCFC({
url: "path/file.cfc", // your CFC
method: myFunction,
data: {},
success: function(data){ showResults(data); }
});
showResults is called on success and data contains the json data. Use
Firebug or something to see what the format of the json data is (it's
very compact and gives you recordcount and colnames if you're
returning query data).
- Jack
Gareth Hughes wrote:
I'd like to see those code snippets Jack :) I looked at ajaxCFC a
while back but didn't have time to figure things out so seeing some
examples would be a great help.
.....