ajaxCFC and 0 Return Values
I've been using ajaxCFC on a project at work and I ran into an issue today which I thought I'd share.
Say you have a simple ajax component:
<cfcomponent extends="ajax">
<cffunction name="echo" output="no" access="private">
<cfargument name="num" required="yes" type="numeric">
<cfreturn val(arguments.num) />
</cffunction>
</cfcomponent>
You set up a call to this method like so:
<html>
<head>
<title>echo number example</title>
<script type='text/javascript'>
_ajaxConfig = { '_cfscriptLocation':'echoNumber.cfc',
'_jsscriptFolder':'../js',
'debug':true};
</script>
<script type='text/javascript' src='../js/ajax.js'></script>
<script type="text/javascript">
function doEcho() {
DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'echo', 0, doEchoResult);
}
// call back function function doEchoResult (r) {
alert(r);
}
</script>
</head>
<body onload="doEcho();">
<p>Nothing Happens!</p>
</body>
</html>
This results in the following response:
HTTP/1.1 200 OK
Connection: close
Date: Wed, 07 Mar 2007 18:14:36 GMT
Server: Microsoft-IIS/6.0
Content-Type: text/html; charset=UTF-8
_3952_1173291282046 = 0;
DWREngine._handleResponse('3952_1173291282046', _3952_1173291282046);
This looks fine, however the callback function doEchoResult never gets called. The reason is the DWREngine._handleRespone function checks the result before calling the callback function.
DWREngine._handleResponse = function(id, reply) {
...
if (handlers && reply) {
...
try {
if (handlers.callback) handlers.callback(reply);
}
catch (ex) {
DWREngine._handleMetaDataError(handlers, ex);
}
}
...
}
The problem here is that the reply argument (the _3952_1173291282046 variable in this example) will be evaluated to false so the callback never gets called.
Now the DWREngine code could be updated to handle this by checking that reply != null, however I'm a little leary of changing core framework code. Plus I haven't really taken a good look at the DWREngine code to know if this will cause any other issues. In the end I decided to modify my component function to work around this issue rather than change the core ajaxCFC files. I've submitted a bug to the RIAForge project, so this may get fixed in a future release. (Or maybe Rob Gonda will chime in and tell me I'm doing things all wrong. :)


