Blocking ColdFusion Debugging for AJAX Requests

This post is more than 2 years old.

This question came in via Twitter today (why, oh why did I start monitoring all ColdFusion mentions in Twitter??) - how does one disable ColdFusion debugging when using Ajax. This is an important question as ColdFusion's default debug output can really screw with Ajax requests. Consider the simple example of loading content into a div:


I took this line from the last InsideRIA blog entry I wrote - basically it calls a ColdFusion service to reverse a string. If I enable ColdFusion debugging, the initial page looks likes so:

But when I fire off an Ajax request to reverse the string, check what comes back:

Yeah, that's so not hot. Luckily it is pretty easy to avoid. I've blogged before about how you can sniff the request headers to check for an Ajax based request. The article focuses on jQuery, but Cutter has assured me the same header exists in ExtJS. (Cutter did some more digging and he believes most JS framework peeps are standardizing on it.)

So given that we can check for an Ajax header in the request, we can use that to turn off debugging using the cfsetting tag and the onRequestStart method:

<cffunction name="onRequestStart" returnType="boolean" output="false"> <cfargument name="thePage" type="string" required="true"> <cfset var reqData = "">
&lt;!--- is it ajax ---&gt;
&lt;cfset reqData = getHTTPRequestData()&gt;
&lt;cfif structKeyExists(reqData.headers,"X-Requested-With") and reqData.headers["X-Requested-With"] eq "XMLHttpRequest"&gt;
	&lt;cfsetting showdebugoutput="false"&gt;
&lt;cfreturn true&gt;


That's it. Of course, that isn't the only way to do it. If you work with ColdFusion 8's built in Ajax UI items, you will notice they pass a URL parameter, _cf_nodebug=true. If you add that to any query string than debugging will be disabled. (Actually, it really, reall turns off debugging. See this blog entry for more details.)

You could also disable debugging by request path, or if the request is to a CFC, or if 'json' appears in the URL. You get the idea. Anyway, I hope this helps.

p.s. Don't forget - if you use ColdFire, you don't have to worry about any of this. Are you using ColdFire yet?

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by anthony posted on 5/1/2009 at 3:56 AM

Apparently Railo and BlueDragon don't support the "_cf_nodebug=true" url parameter. Maybe I should submit those as feature requests.

Comment 2 by Justin Carter posted on 5/2/2009 at 5:13 PM

ColdFire is the best debugging solution ever, I couldn't recommend it highly enough :)

Comment 3 by Doug posted on 5/4/2009 at 8:16 PM


Thanks for pimping it, Ray!

Comment 4 by Doug posted on 5/4/2009 at 8:31 PM

Oops, nevermind, I just now noticed that you guys only posted it a month ago-- I guess my fault for not following you every day. ;)

Comment 5 by Chad Mefferd posted on 3/31/2010 at 7:57 PM

Thanks again for making life easier yet again. Very helpful.