Skip to main content
deleted 4 characters in body; edited tags
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

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>

I'm using ColdFusion 8.

Direct CFC calls are flushed when the method returns.

  Either way onRequestEnd will stop debug output from being returned for AJAX requests.

Keep If Statement Additional Regular Expression search on every AJAX call. Direct CFC calls return quicker. Direct CFC call may not be trimmed.

Remove If Statement (inner code executes for all AJAX requests) Direct CFC calls' value is stored in a variable. AJAX calls to pages return quicker. All AJAX responses are trimmed.

<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>

Direct CFC calls are flushed when the method returns. Either way, onRequestEnd will stop debug output from being returned for AJAX requests.

Keep If Statement

Additional regular expression search on every AJAX call. Direct CFC calls return quicker. Direct CFC call may not be trimmed.

Remove If Statement (inner code executes for all AJAX requests)

Direct CFC calls' value is stored in a variable. AJAX calls to pages return quicker. 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>
Added ColdFusion version to given section.
Source Link

I'm using ColdFusion 8.

Direct CFC calls are flushed when the method returns.

Direct CFC calls are flushed when the method returns.

I'm using ColdFusion 8.

Direct CFC calls are flushed when the method returns.

Tweeted twitter.com/#!/StackCodeReview/status/120030812241530880
Source Link

Should I treat direct CFC Calls differently than Page Requests?

Should I leave in <cfif reFindNoCase( "\.cfc$" , targetPage ) eq 0> or not?

Direct CFC calls are flushed when the method returns.

Either way onRequestEnd will stop debug output from being returned for AJAX requests.

Keep If Statement Additional Regular Expression search on every AJAX call. Direct CFC calls return quicker. Direct CFC call may not be trimmed.

Remove If Statement (inner code executes for all AJAX requests) Direct CFC calls' value is stored in a variable. AJAX calls to pages return quicker. All AJAX responses are trimmed.

<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>