Ask Ben: Accessing Cached CFCs With AJAX via Remote Proxies

<cfcomponent
	output="false"
	hint="I provide remote proxy functionality for AJAX calls that need to access the application.">
 
 
	<cffunction
		name="NewResponse"
		access="public"
		returntype="struct"
		output="false"
		hint="I create a new instance of the unified response object used in the AJAX requests.">
 
		<!--- Define the local scope. --->
		<cfset var LOCAL = {} />
 
		<!--- Create a response object. --->
		<cfset LOCAL.Response = {
			Success = true,
			Errors = [],
			Data = ""
			} />
 
		<!--- Return new response object. --->
		<cfreturn LOCAL.Response />
	</cffunction>
 
 
	<cffunction
		name="AddResponseError"
		access="public"
		returntype="struct"
		output="false"
		hint="I add the given error to the given response object.">
 
		<!--- Define arguments. --->
		<cfargument
			name="Response"
			type="struct"
			required="true"
			hint="I am the response object to which an error is being added."
			/>
 
		<cfargument
			name="Property"
			type="string"
			required="true"
			hint="I am the property in error."
			/>
 
		<cfargument
			name="Error"
			type="string"
			required="true"
			hint="I am the error message."
			/>
 
		<!--- Define the local scope. --->
		<cfset var LOCAL = {} />
 
		<!--- Create the error struct. --->
		<cfset LOCAL.Error = {
			Property = ARGUMENTS.Property,
			Error = ARGUMENTS.Error
			} />
 
		<!--- Add error to the response. --->
		<cfset ArrayAppend(
			ARGUMENTS.Response.Errors,
			LOCAL.Error
			) />
 
		<!--- Flag the response as non-successful. --->
		<cfset ARGUMENTS.Response.Success = false />
 
		<!--- Return the updated response. --->
		<cfreturn ARGUMENTS.Response />
	</cffunction>
 
</cfcomponent>

For Cut-and-Paste