Pages

Sunday, June 9, 2013

Cakephp 2.0-Create 0bserve field equivalent with new jshelper

Many things have changed in v2.0 of cakephp removal of ajaxhelper is one of them in its plce we have a new helper called jshelper() to perform similar tasks here is how to use observe field with jshelper in cakephp 2.x


 <?php  
 echo $this->Js->get('#category')->event->('change',$this->JS->request(array(  
 'controller'=>'contributers',  
 'action'=>'changevideos'),  
 array(  
 'update'=>'#videocontainer',  
 'async'=>true,  
 'dataExpression'=>true,  
 'method'=>Post,  
 'data'=>$(this).serialize()'),  
 false))  
 ?>   

Where #category is the id of element which fires event and #videocontainer is the id of div which is updated of data from controller "contributors" and its action "changevideos"

2 comments:

  1. but if i want a return, for example, i'm trying to change the values of a form when the option froma a select is changed.

    ReplyDelete
    Replies
    1. you can return json in that case from the page and then callback a function on success where you can set your form data.

      Delete