ColdFusion debugging breaks jQuery AJAX calls

{ Posted By : Eric Cobb on June 17, 2010 }
2071 Views
Related Categories: Tips 'n Tricks, jQuery, ColdFusion

This may be a no-brainier for some, but I fought with it for about 2 hours yesterday so I wanted to make note of it in case it happened again.

I had a situation where my code worked correctly on my local development machine, but wouldn't work in our staging environment. The exact problem was that I was using jQuery to call a CFC, which returned some JSON, and jQuery then populated a div with it. Pretty basic stuff. But for some reason, on our staging server jQuery encountered problems and would never populate the div, even though I could see in FireBug where the CFC call was returning the JSON correctly. All code was identical in every comparison, and both sites were using the same database so the data was identical as well.

It took me a while, but I finally figured out what was happening. Long story short, our staging server had CF debugging turned on, and it was appending the debug info to the end of the JSON being returned from my CFC call, which then threw errors in jQuery. Locally I have debugging turned on as well, but it's going to ColdFire/Firebug, so I never saw the problem. The JSON packet being returned is so large that it doesn't show all of it in FireBug, so it wasn't until I opened it in a FireFox tab that I saw the debugging info being appended to the end.

Anyway, a simple "cfsetting showdebugoutput="false"" fixed the issue.

Comments
Jen's Gravatar Nice work. I use jQuery and CFCs quite a bit. I'll keep this mind.
# Posted By Jen | 6/17/10 10:35 AM
gus's Gravatar That's not specific to JQuery, any ajax call can break with debugging turned on.
# Posted By gus | 6/17/10 4:39 PM
Christopher Chin's Gravatar I add <cfsetting showdebugout=false> at the top of my cfc's, but yeah this got to me too for a bit.
# Posted By Christopher Chin | 6/17/10 7:00 PM
Christopher Chin's Gravatar oops..yeah, that's what you wrote at the bottom of your post...duh..didnt read it thru.
# Posted By Christopher Chin | 6/17/10 7:00 PM
Larry C. Lyons's Gravatar Just a short comment. The dockable option in the CF Admin is compatible with jQuery Ajax calls.
regards,
larry
# Posted By Larry C. Lyons | 7/26/10 6:01 PM
Eric Cobb's Gravatar @Larry - Hey, thanks for the tip. That's good to know.
# Posted By Eric Cobb | 7/26/10 8:30 PM