Ajax request in cakephp 2.x

show.ctp

<?php echo $this->Html->script('jquery', FALSE); ?>

<?php

echo $this->Form->create('Count', array('action'=>'ajaxShow'));
echo $this->Form->input('field', array('id'=>'field'));
echo $this->Js->submit('Send', array(
'before'=>$this->Js->get('#sending')->effect('fadeIn'),
'success'=>$this->Js->get('#sending')->effect('fadeOut'),
'update'=>'#success'
));

?>

<div id='sending' style="display:none"> Counz[dot]gif will be displayed </div>
<div id='success'></div>

controller

var $name = 'count';

    public $helpers = array('Js' => array('Jquery'));
    //var $helpers = array('Ajax', 'Javascript');
    var $components = array('RequestHandler');
public function ajaxShow(){
         $this->layout = 'ajax'; 
        if($this->RequestHandler->isAjax()){  
            $this->render('success', 'ajax');
        }else{
            $this->set('for_map', $this->count->find('all'));

        }
    }

success.ctp

<p>It's working</p>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s