JSON and CakePHP

Last few articles in this blog are only for stupid problems and unfortunately this one will be the same.

I had to use JSON to update some chained select boxes. I am using one jQuery plugin for this. The problem is that if you code, most likely your debug setting in the core.php file is set to 1 (or 2). This way the developer can see errors from CakePHP.

When the level is set to 1, at the end of the page, there is an comment, displaying the processing time for the page, but when you use JSON, this comment causes troubles (probably, because JSON doesn’t accept this type of comments) and the JS fail to process the response.

In order to check JSON, I needed to disable set debug level to 0 and after this to reset it again to 1 (for debugging purposes in other parts of the application).

So, the conclusion: bear in mind, that JSON doesn’t like HTML comments.

Hope this helps.

5 thoughts on “JSON and CakePHP

  1. Nik Chankov Post author

    Thanks for the hints Abba Bryant, actually I knew about setting the Configure::write(’debug’, 0); for the specific action, but it was annoying for the first time 🙂

    About parseExtensions – I’ve read about it, but I’ve never used it, I should try…

    Thanks again!

  2. Daniel Hofstetter

    As long as you know what you do I don’t see any problems in editing this file: the file is in the app folder and if you use an advanced installation you have to touch it anyway.

  3. Nik Chankov Post author

    You are right, it’s in APP, probably I need to touch, because I am tired from switching on and off debug, as well as I haven’t used this parsing time anyway. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *