Dependent Dropdown Issue?help Needed

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);

    }

}

where something i doing wrong

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’.

I see in developer tools and in network tab this error occure TypeError: jQuery(…).on is not a function @ http://localhost/yii/myapp/index.php?r=site/dropdown:951

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.

ye syou are right i was using old jquery version but now i use yii jquery like this


<script type="text/javascript" src= <?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>"></script>

That error is gone but now this error comes


[01:58:04.647] POST http://localhost/yii/myapp/index.php?r=SiteController/dropdown [HTTP/1.0 404 Not Found 41ms]

i dont understanding from where it going to an other page request may be from here

‘url’=>CController::createUrl(‘sitecontroller/dynamiccities’),

please help

For starters, the route should be ‘site/dynamiccities’, not ‘SiteController/dynamiccities’.

I’d recommend going through the Yii guide from start to finish as you seem to be misunderstanding some of Yii’s main principles.

I don’t know where your route ‘SiteController/dropdown’ has come from; I suspect it’s in part of the code that you haven’t shown us.