AjaxCFC - the Client Side
As promised, here is a quick rundown of the client side part of AjaxCFC.
The first part in the client side of AjaxCFC is to include the javascript files.
_ajaxConfig = {'_cfscriptLocation':'echoTest.cfc', '_jsscriptFolder':'js'};
_ajaxConfig will store the location of the listener CFC and location of the “js” folder which is included in the ajax.zip file that comes with AjaxCFC. The use of _cfscriptLocation variable is optional as you may specify the CFC location directly in the Ajax call.
You will have an ajax calling function and a call-back function; however, none of them are mandatory, because depending on your needs you may not need to know the result of your call, or you may not need to enclose your ajax call in a function.
To invoke an ajax component you need to use DWREngine._execute which my colleague, Ashish has already explained.
The call-back function will always take one argument, which is the return of the method called within the CFC object.
AjaxCFC will allow you to return almost all simple or complex object to the JavaScript callback function: strings, numbers, arrays, structures and queries.
We have a preferance of structures over the other objects. The callback function will always take one argument, which is the return value of the invoked CF function.
The JavaScript function will receive the number or string just like any regular JavaScript call.
To retrieve the recordcount, you can loop your data through a built-in function, result.getRowCount(), which will return the equivalent to query.recordcount. You can always use sDumper(result) to show you exactly what is being sent back to your handler.
Comments
Post a comment