Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9175205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:52:32+00:00 2026-06-17T16:52:32+00:00

After an ajax request i got one array from my controller as response, how

  • 0

After an ajax request i got one array from my controller as response, how can I use this array values in my dropdown list?

Answer

in my view I have

echo CHtml::dropDownList('client_id', '',CHtml::listData($model,'client_id','client_name'), array(
'ajax'=> array(
'type'=>'POST',
'url'=>Yii::app()->baseUrl.'/index.php?r=page/dynamicDropdownList',
'update'=>'#program_id',
'empty'=>'-Select a Client-')));

// I need to populate the response array in this dropdownlist
echo CHtml::dropDownList('program_id','', CHtml::listData($result,'program_id', 'program_name'));

in my controller

 public function actionDynamicDropdownList()
 {

    if($_POST['client_id'] > '0') {
        $result = Yii::app()->db->createCommand()->select('program_id, program_name')->from('program')->where('client_id='.$_POST['client_id'].'')->order('program_name')->queryAll();
        $this->render('admin', array(
            'result' => $result,
        ));

    }

   }

Another Problem

Now I got everything working except the second drop downlist is also showing the values of 1st dropdown list with the result.

solution:- I have parse the response and show it in the dropdownlist

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:52:33+00:00Added an answer on June 17, 2026 at 4:52 pm

    This is how your controller should look like:

    public function actionIndex() {
    
            $model = new SearchForm();
            if ($_GET['SearchForm']) {
                $model->attributes = $_GET['SearchForm'];
            }
    
    //here is where you put your criteria or query commands
    
            if ($_GET['ajax']) {
                $this->renderPartial('index', array(
                    'model' => $model,
                ));
            } else {
    
                $this->render('index', array(
                    'model' => $model,
                ));
            }
        }
    

    You catch the data from ajax or GET and you do something with it, then you pas the data to the view;

    And this should be what the vies contains:

    <? echo $form->dropDownList($model, 'position_type', CHtml::listData(PositionType::model()->findAll(array('condition' => 'status=1')), 'id', 'name'), array('class' => 'postdropdown2', 'empty' => array(-1 => 'All'), 'onchange' => 'showDiv(this.value,1);')); ?>
    

    You have to work with data received using ajax in the controller, as it is not visible in the view, if it was not passed using render or renderpartial

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read the http-response by ajax request. As an echo-server I use
I m sending ajax request using Firefox. After completing the request I got a
I've got 2 ajax requests on one page. I ran first request and separately
I got this example demonstrating AJAX from Stoyan Stefanovs Object Oriented JavaScript at page
On page load i'm sending one AJAX using jQuery .ajax function. After i got
i was wondering how/where to write a callback function after an ajax request is
I'm sending ajax request and i have appended the result on a div. After
how can i disable live('click', function...) method and then after ajax call (depending on
I certainly can't solve this problem by myself after a few many days already
I'm trying to fetch some data from Wikipedia via AJAX. After fiddling with the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.