Cakephp 2.x 中的 Ajax 請求

在 cakephp 中使用 ajax 的另一種方法。Cakephp 為 ajax 請求提供自己。請看例子。

 $data = $this->Js->get('#id')->serializeForm(array('isForm' => true, 'inline' => true));
//on click send request to controller and displays response data in view
$this->Js->get('#button-id')->event(
        'click', $this->Js->request(
                array('controller' => 'Users', 'action' => 'add'), array(
            'update' => '#time', // field you wish to update
            'data' => $data, // Form Data in serialize form
            'async' => true,    
            'dataExpression'=>true,
            'method' => 'POST' // method get or post
                )
        )
);