Processing Ajax requests
It's no secret that Ajax has revolutionized web development and helped developers build and deliver engaging applications which have a real-time feel to them.
In this recipe, we'll look at how easy it is to handle Ajax requests in CakePHP and give you an introduction to the possibilities at your fingertips.
Getting ready
For this recipe, we'll reuse the books
database table from the previous chapter. We'll also need a view for our inventory_index().
action, so create a file named inventory_index.ctp
in app/View/Books/
.
How to do it...
Perform the following steps:
Add the following
beforeFilter()
method to theBooksController
class:public function beforeFilter() { parent::beforeFilter(); if ($this->request->is('ajax')) { $this->response->disableCache(); } }
In the same class, add the following
inventory_index()
method (we will utilize theinventory
prefix added in the previous chapter):public function inventory_index() { $this->set('books', $this...