Bulid Ajax In Yii

I need to understand how to build Ajax request in Yii. I searched on the Yii website and found the following article :


I wrote the code and I tested it on my localhost ? but for some reason it did not work.

For a first attempt I only wanted to do something simple. I wanted to print the result of another action on my page by using Ajax. The text that I want to be displayed is ‘Hi’.

This is how mu code looks like for that action:



/* @var $this CurrentController */






<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(



)); ?>


echo CHtml::dropDownList('country_id','', array(1=>'USA',2=>'France',3=>'Japan'),


'ajax' => array(

'type'=>'POST', //request type

'url'=>CController::createUrl('currentController/dynamiccities'), //url to call.

//Style: CController::createUrl('currentController/methodToCall')

'update'=>'#city_id', //selector to update

//'data'=>'js:javascript statement' 

//leave out the data key to pass all form values through



//empty since it will be filled by the other dropdown

echo CHtml::dropDownList('city_id','', array());



<?php $this->endWidget(); ?>

</div><!-- form -->



class CurrentController extends Controller


public function accessRules()


		return array(

			array('allow', // allow authenticated user to perform 'create' and 'update' actions






public $country_id;

	public function actionIndex()





public function actionDynamiccities() /// Called Ajax




    	echo CHtml::tag('option',







Unfortunately I’m not getting the desired result. What I get is:

[list=1][]drowpdown list contains country array.[]another drowpdown list but empty ?![/list] How should I fix my example code so it would work? Can anyone see what I am doing wrong?

Thanks in advance

Tempra Requests Result :


So it’s send data .