cfajaxproxy and a common gotcha
Tags: General, Ajax, Coldfusion
One of the best things that was introduced into ColdFusion was the cfAjaxProxy tag, however I would like to add that to the unwary there is a very huge gotcha. And can make for debugging a little hard.
The problem with creating a mapped object for JavaScript is that is is transferred over the wire, what this means is that when the call is made back to the server it re-instantiates the object for each and every call.
So if you are setting variables that are needed to be returned, this can cause a major headache as by convention we think that it works when we write the same code in normal CFML.
That is because the object is still alive for the duration of the request, Ajax is different because the request has come and gone.
So what is the solution, well you can do it the singleton way and persist the object in a session or application scope. And use the ajax call as a controller to the rest of your application.
But this is not the first time I have heard people getting caught up with this problem, a very easy mistake to make. And unless you are aware how a request is made between the server and client and commit that to memory you can be tripped up each and every time.
I hope this helps a lot more people become aware of this little gotcha.
-
Another unfortunate gotcha is cfajaxproxy announces to the world via JavaScript all of your remote methods (view the source).
One thing I do is I have one cfc with one remote method called "process". It forwards all my method calls to persistent objects along with the accompanying variables.
e.g. Javascript<script>
var proxyO = new ProxyCFC();
proxyO.process({execute:'doSomethingMethod',var1:var1Val, var2:var2val, varStruct:varSTructObj});
</script># Posted By Yaron | 9/25/09 6:15 AM



TweetBacks