I'm using ColdFusion 8.
Direct CFC calls are flushed when the method returns.
Either way onRequestEnd, onRequestEnd
will stop debug output from being returned for AJAX requests.
Keep If Statement Additional Regular Expression
Additional regular expression search on every AJAX call. Direct Direct CFC calls return quicker. Direct Direct CFC call may not be trimmed.
Remove If Statement (inner code executes for all AJAX requests) Direct
Direct CFC calls' value is stored in a variable. AJAX AJAX calls to pages return quicker. All All AJAX responses are trimmed.
I'm using ColdFusion 8.
<cfcomponent output= "false">
<cfset this.name= "AJAX Debug Output" />
<cffunction name= "onRequestEnd"
returnType= "void"
hint= "I run on the end of requests (how clever).">
<cfargument name= "targetPage"
hint= "Path from the web root to the requested page." />
<cfif isAJAXRequest()>
<cfsetting showDebugOutput= "false"
enableCFOutputOnly= "true" />
<!--- Response from CFC is already flushed to browser. Skip output. --->
<cfif reFindNoCase( "\.cfc$" , targetPage ) eq 0>
<!--- If AJAXResponse is not set, then generated content is response. --->
<cfparam name= "request.AJAXResponse"
default= "#getPageContext().getOut().getString()#" />
<cfcontent reset= "true" />
<cfoutput>#trim( request.AJAXResponse )#</cfoutput>
<cfabort />
</cfif>
</cfif>
</cffunction>
<cffunction name= "isAJAXRequest"
output= "false"
access= "private"
hint= "I check to see if the request came across with ajax headers">
<cfif structKeyExists( getHTTPRequestData().headers , "X-Requested-With" )>
<cfreturn true />
</cfif>
<cfreturn false />
</cffunction>
</cfcomponent>