Recently i have started another CakePHP project. i found that the example in Ajax implementation on CakePHP @ 2 should be changed as follow.
ajax_controller.php
<?php Class AjaxController extends AppController { var $name = 'Ajax'; var $helpers = array('Form','Html','Javascript', 'Ajax'); var $components = array('RequestHandler'); function afterAjaxAction () { // get the $this->data to collect the form information // save the object to database // render the after_ajax_call.ctp $this->render('/elements/layout/after_ajax_call'); } }
view.ctp
<div id='ajaxDiv'> <!-- create the form --> <?php echo $form->create(<object to be saved>); ?> <?php echo $form->input(...); ?> <?php echo $form->input(...); ?> <?php echo $form->input(...); ?> <?php echo $ajax->submit('Submit', array('url' => array('controller'=>'ajax', 'action'=>'afterAjaxAction'), 'update'=>'ajaxDiv', 'before' => <OPTIONAL - Ajax callback option for javascript>)); ?> <?php echo $form->end(); ?> </div>
Done =)