Ajax Does Not Respond In Dropdown

Hello Yii Community!

I have a bit of trouble in updating my form in dropdown,

This is partial view code

<div class="row">

	&lt;?php if(&#036;users-&gt;isNewRecord) { 


			  echo &#036;form-&gt;labelEx(&#036;departments,'dept_name'); 


			  &#036;data = Departments::model()-&gt;findAll(array('order'=&gt;'dept_name')); 


              &#036;data = CHtml::listData(&#036;data,'dept_id','dept_name'); 


              echo CHtml::dropDownList('department', &#036;departments,&#036;data,


              array(


                'prompt'=&gt;'Select Department',


                'ajax' =&gt; array(


                'type'=&gt;'POST', 


                'url'=&gt;CController::createUrl('updatesection'), 


                'update'=&gt;'#Sections_sec_name', 


              ))); 


		  } else {


			  echo &#036;form-&gt;labelEx(&#036;departments,'dept_name'); 


			  &#036;data = Departments::model()-&gt;findAll(array('order'=&gt;'dept_name')); 


              &#036;data = CHtml::listData(&#036;data,'dept_id','dept_name'); 


              echo CHtml::dropDownList('department', &#036;departments,&#036;data,


              array(


                'prompt'=&gt;'Select Department',


                'options' =&gt; array(&#036;users-&gt;userSec-&gt;secDept-&gt;dept_id=&gt;array('selected'=&gt;true),


                'ajax' =&gt; array(


                'type'=&gt;'POST', 


                'url'=&gt;CController::createUrl('updatesection'), 


                'update'=&gt;'#Sections_sec_name', 


              )))); 


		  }


	?&gt;


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;sections,'sec_name'); ?&gt;


    &lt;?php echo &#036;form-&gt;dropDownList(&#036;sections,'sec_name', 


		   array('empty'=&gt;'Select Sections..',


		   ));


	?&gt;                        


&lt;/div&gt;

In department dropdown list, the data will be based on the save values on the database as well the section.

But if the department dropdown is changed the ajax won’t work like in the Create Form.

What seems to be the problem. Thanks for the help!

  1. check for action path

  2. check with firebug in firefox, ajax POST is to which action

  3. remove unwanted jquery and other scripts.

In addition to what Rajith R says, it is worth mentioning that you should re-factor your code and move the business logic out of the view file. Doing database calls in a view file is generally considered to be bad practice.