If you are developing a CakePHP application and you have the debug value set to anything greater than 0 in your config/core.php file, you will find that Ajax requests will also get the extra information appended to the output.
In order to circumvent this add this to your “app_controller.php” file (which sits directly inside the “app/” dir, rather than in “app/controllers”):
<?php
class AppController extends Controller {
var $components = array('RequestHandler');
var $helpers = array('Html','Form','Ajax');
function beforeFilter() {
if ( $this->RequestHandler->isAjax() ) {
Configure::write('debug',0);
}
}
}
?>
Note that while this will disable the debugging output, it will also have other affects too (for the life of the Ajax Request) like extending the length of time that the “schema” is cached. This should make little or no difference, but is worth remembering.
Nice tip.
I’ve been appending Configure::write(‘debug’,0); to my controller actions.
Your method might get a bit tricky if you are debugging something with multiple ajax elements and you only need to debug that last one in the chain though. ie. you only need to switch off debugging for a few ajax requests.
Richard@Home
19 Feb 09 at 6:47 am
I see what you’re saying Richard, but when using Ajax I tend to favour put debugging data in logs so as not to break the JS that is parsing the output. I guess I should write something on general CakePHP debugging methods!
pete
19 Feb 09 at 11:52 pm
Thanks for this. I mostly tend to work with json when in ajax and the debug output is a pain when trying to parse the data.
John
21 Nov 09 at 3:29 pm
[...] otaqui.com [...]
[SOLVED]Disable Debug Output for Ajax in CakePHP « RussenReaktor’s Weblog
15 Dec 09 at 9:57 pm