Use a view. Don't return directly from the Controller. You can either:
- Use data views (from cake > 2)
- render an empty view in an empty layout
The data views approach is very good however you will need todo some setup as described in the link - parseExtensions, add the RequestHandlerComponent, etc. It is cleaner than the second option. Check the documentation and decide which one is for you. The second option is the "old way to do it". Anyway if you want to do it the by the second way this is what you need to do:
- Create an
ajax.ctp
layout file underView/Layouts
. Can be called whatever you like - Have ONLY the
content_for_layout
display in it:<?php echo $content_for_layout; ?>
- Create a view:
<?php echo json_encode($fechas);?>
- Include the
RequestHandler
component if you are not getting the right headers In your controller after you get the data:
$this->set('fetchas', $fechas);
$this->render('your_view's_name_here')