Using CakePHP for 6+ years (starting with 1.2) Core Developer since 2+ years Active blogger about CakePHP issues and solutions Germany (Berlin) Passionate PHP and Open Source Developer
/** * AJAX action to get favorites * * @return string */ public function favorites() { $this->autoRender = false; // We don't render a view in this example $this->request->allowMethod(array('ajax')); // No direct access via browser URL $data = array( 'content' => ..., 'error' => '', ); $this->response->body(json_encode($data)); } GET /controller_name/favorites.json
/** * AJAX action to get favorites * * @return void */ public function favorites() { $this->request->allowMethod(array('ajax')); // No direct access via browser URL $data = array( 'content' => ..., 'error' => '', ); $this->set(compact('data')); // Pass $data to the view $this->set('_serialize', 'data'); // Let the JsonView class know what variable to use }