Problem with dependent dropdown

Im trying to create a dependent dropdown, but I can’t get it to work.

Here is my code:

_search:




<?php

	echo $form->DropDownList($model,'country', array(1=>'Sweden',2=>'Finland',3=>'Denmark'),

		array(

		'ajax' => array(

			'type'=>'POST',

        	'url'=>CController::createUrl('CountryController/dynamiccity'),

        	'update'=>'#'.CHtml::activeId($model,'city')

		))); 

 ?>


<?php echo $form->dropDownList($model,'city',array()); ?>



CountryController:




public function accessRules()

	{

		return array(

			array('allow',  // allow all users to perform 'index' and 'view' actions

				'actions'=>array('index','view'),

				'users'=>array('*'),

			),

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

				'actions'=>array('create','update','dynamiccity'),

				'users'=>array('@'),

			),

			array('allow', // allow admin user to perform 'admin' and 'delete' actions

				'actions'=>array('admin','delete'),

				'users'=>array('admin'),

			),

			array('deny',  // deny all users

				'users'=>array('*'),

			),

		);

	}


public function actionDynamiccity() {

            $country_id = $_POST['country'];

            $data=Citys::model()->findAll('country_id=:country_id',

                    array(':country_id'=> $country_id));


            $data=CHtml::listData($data,'city_id','city_name');

            foreach($data as $value=>$city_name)  {

                echo CHtml::tag('option',

                   array('value'=>$value),CHtml::encode($city_name),true);

            }

     }



I have looked at these posts

http://www.yiiframework.com/wiki/24/

http://www.yiiframework.com/forum/index.php/topic/11531-solved-how-to-create-dependent-dropdown-lists/

There is no error provided but the second dropdown is empty no matter what I choose in the first dropdown.

Anyone see any errors in the code?

Do I need to activate-functionallity ajax somewhere?

check you browser console does it display in error?

when I load first load the page the console is empty but when i change the value in the first dropdown this error shows up in the console.

In chrome:




POST myurl/index.php?r=CountryController/dynamiccity 404 (CHttpException) jquery.js:8102

jQuery.ajaxTransport.send jquery.js:8102

jQuery.extend.ajax jquery.js:7580

(anonymous function) index.php:277

jQuery.event.dispatch jquery.js:3256

jQuery.event.add.elemData.handle.eventHandle



Seems to be something wrong with the url. My controller is named CountryController as a file but in the url it should be just Country.

Tried changing ‘url’=>CController::createUrl(‘CountryController/dynamiccity’), to ‘url’=>CController::createUrl(‘Country/dynamiccity’), but then I dont get any error in the console

Ideas?