HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Should I treat direct CFC Calls differently than Page Requests?

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
callsdifferentlycfcthandirectpageshouldrequeststreat

Problem

Should I leave in ` 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.

I'm using ColdFusion 8.


    

    
        

        
        

            
            

            
            #trim( request.AJAXResponse )#
            

        

    

    
        

    

    

Solution

And, if you are using CF 9.0.1 you don't have to worry about the debug output at all, on direct CFC Requests. Starting with 9.0.1, CF will automatically suppress the debug output. (Thank God)

A few years back, Ray and I were hashing out how to target a request via it's header, and came up with this:



That worked great, as all of the Ajax libraries (that we tested) were using the same thing. That is, until JQuery released 1.6, at which point they created a custom header type (jqXHR, I think) that they use with requests.

Code Snippets

<cfif structKeyExists(reqData.headers,"X-Requested-With") and reqData.headers["X-Requested-With"] eq "XMLHttpRequest">

Context

StackExchange Code Review Q#5086, answer score: 3

Revisions (0)

No revisions yet.