Populate Select box dynamically by ajax in Cakephp

To populate a select box by cakephp ajax functionality.
Step 1.
In the end of your view (.ctp)file.This is your javascript code in cake.

$this->Js->request(array('controller'=>'ControllerName','action'=>'ajax_call'), array(
'async' => true,
'method' => 'post',
'data'=> $this->Js->serializeForm(array(
'isForm' => true,
'inline' => true))

Step 2.
In your controller file create function with that returns options string

public $helpers = array('Js'); //load Js helper
public function getBySubject(){
		$this->autoRender=false; //prevent to load default layout
//your code

step 3.
In the end or your layout file after your loaded scripts

if (class_exists('JsHelper') && method_exists($this->Js, 'writeBuffer')) echo $this->Js->writeBuffer();
// will write your cached scripts
Share on Google+Share on FacebookTweet about this on TwitterEmail this to someone