Search code examples
phpajaxjsoncakephpcakephp-2.1

CakePHP 2.1 JsonView


I'm using the new CakePHP 2.1 and would like to use the JsonView to make my controller respond to an AJAX request created by jQuery on the client side.

However, this should be done automatically with the JsonView according to the documentation.

http://book.cakephp.org/2.0/en/views/json-and-xml-views.html

I added this line in my routes.php file

Router::parseExtensions('json');

And in my controller I have

$this->RequestHandler->setContent('json', 'application/json' ); 
$bookings = $this->Bookings->find('all');

$this->set('bookings', $bookings);  
$this->set('_serialize', 'bookings');

Then the view should be obsolete, but when I call this, it still serves a page which is pointing to a missing view.


Solution

  • Does the url you are calling ends on '.json'?