When CakePHP debugging is set to anything above 0, you’re in development mode and it’ll append the sql log on to the end of any view. This is great for general development but if you’re trying to test your ajax functionality, you’ll get that sql log in the ajax response.
I’ve seen some solutions that have you put something in your AppController’s beforeFilter so that it’ll detect if the request is ajax. I tried it and it didn’t work. I figure it was for an older version (of the 1.2.* branch). I also saw a solution that isn’t good. It makes you turn of all debugging so that the entire app is in production mode, I didn’t like that either.
My quick fix was simple enough. Turn debugging off locally for the ajax action.
public function ajaxy() {
// Because it is Ajax, we need to remove the SQL log.
Configure::write('debug', 0);
/*
.... more code ....
*/
}
So why this is that better? You can decide if you want it or not, just comment it out. It’s specific for that one action. If your controller is going to entirely ajax, you could easily then put it in the controller’s beforeFilter.
There should be a more elegant solution than this.