calling a coldfusion function from another function via ajax rendering an error
Here's the deal: I am sending an ajax request to a coldfusion function, which then calls another function inside the same component. Here are the two functions:
<!--- test--->
<cffunction name="deleteMission" access="public" output="No" returntype="struct">
<cfscript>
var returnData = structNew();
structAppend(returnData, get开发者_开发技巧Test());
returnData.test2 = "test2";
</cfscript>
<cfreturn returnData>
</cffunction>
<!--- test2 --->
<cffunction name="getTest" access="public" output="No" returntype="struct">
<cfscript>
var returnData = structNew();
returnData.testing = "TEST";
</cfscript>
<cfreturn returnData>
</cffunction>
Very simple, just returning 2 struct keys in this example. If I call the method test() regularly (ie, on page load via coldfusion), I get the expected results. However, if I call the method test() via AJAX, I receive the error "Variable getTest is undefined." If I remove the call to getTest(), I receive the single struct key back as expected. Anyone have any idea what is going on? I have a feeling it's something simple I've overlooked, but I need some more eyeballs on it at this point... I'm really scratching my head on this one. Thanks!
If you're accessing the component via AJAX, then the access
attribute of your cffunction
should be set to remote
. E.g.
<cffunction name="deleteMission" access="remote" output="No" returntype="struct">
Change your getTest to access="private". Also, Sometimes the StructAppend method does not take in parameters as "function call". So get the value into a variable first and then send that variable to deleteMission.
something like this...
var inpData = getTest();
structAppend(returnData, inpData);
精彩评论