I make a dependent drop down list there is no error but in second drop down showing empty My view code is
<?php
echo CHtml::dropDownList('name','', array(1=>'Gujrat',2=>'Jalalpur',3=>'kpk'),
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('SiteController/dynamiccities'), //url to call.
'update'=>'#unionname', //selector to update
)));
//empty since it will be filled by the other dropdown
echo CHtml::dropDownList('unionname','', array());
?>
And controller code is
public function actionDynamiccities()
{
$data=Location::model()->findAll('name=:name',
array(':name'=>(int) $_POST['unionname']));
$data=CHtml::listData($data,'id','name');
foreach($data as $value=>$name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
}
See what’s happening to the ajax request in your browser’s developer tools.
In chrome, go to the menu, then Tools -> Developer Tools -> Network Tab. Then make a change in the first drop down list and see what happens with the request. You can click into the response to get more details.
A controller action that handles an ajax request may not show you an error in the browser, but it may encounter an error and the ajax may not work. The error should be found in your application/runtime/application.log.
In this particular case $_POST[‘unionname’] will cause an error, because the name of the 1st dropdown is ‘name’, not ‘unionname’.
The method jQuery.on() was added in jQuery version 1.7. I suspect that you’re using an earlier version. You can either use jquery.delegate() or update your version of jQuery.