I have this code as a cffunction that works fine:
<cfcomponent extends="core.core">
<cffunction name="loadService" access="remote" returnformat="JSON">
<cfscript>
objResponse = '{"CONFIG":[["internal"],[ "success"]],"DATA":[["Message1"]]}';
</cfscript>
<cfreturn objResponse>
</cffunction>
</cfcomponent>
I am trying to convert it to a full cfscript function like this:
component extends="core.core"{
remote JSON function loadService(){
objResponse = '{"CONFIG":[["internal"],[ "success"]],"DATA":[["Message1"]]}';
SerializeJSON(objResponse);
return objResponse;
}
}
The first way returns JSON fine and I can process it with jQuery. The second one throws and error “The value returned from the loadService function is not of type JSON.”
I have tried it with and without SerializeJSON and both ways throw that error. I have also tried it without specifying JSON in the function syntax. That does not throw an error but it does wrap wddxpacket info around it. This is what it looks like when I don’t specify JSON:
<wddxPacket version='1.0'><header/><data><string>{"CONFIG":[["internal"],[ "success"]],"DATA":[["Message1"]]}</string></data></wddxPacket>
I am stuck on this. Any help would be great. Thanks!
The correct CFScript syntax in CF9 is:
Technically, “JSON” is not a valid returntype from a function (see here for all returntypes), but when you write:
…you’re basically saying that.
Notice in your tag-based cffunction call, you do not specify a returnType…so guess what it is by default? (hint: any).
It’s easy to mix returnType and returnFormat up. A simple adjustment above and you should be good to go.
Complete Code