Ajax in Yii

I’m using Yii to build my website.

My website requires AJAX technology.

Example: I have a combobox containing a list of user. When I choose a user, a table contain detail of that user appear. All user details are contained in the database. Like that: www.w3schools.com/ajax/ajax_database.asp

But I do not know how to do it in Yii. I follow this guide: www.yiiframework.com/wiki/49/

but I don’t wan’t to click button to change a content, I want content change automatic when i do something. And in controller, I don’t know how to get varriable from view file such as: user in a list …

Can someone help me! Thanks for reading :(

P/s: I can’t post a link in my first post.

Use the onchange event of the select element.

Check the documentation for createUrl.

But how to use onchange event to load a part of webpage using Yii.

I see a code like this:

<?php echo CHtml::ajaxButton ("Update data",


                          array('update' =&gt; '#data'));


But how can i update content without button.

Can you give me some example code?

Sorry for my previous suggestion. You should use configure your htmlOptions for the dropDownList it like this:




    'data'=>array('value' => 'js:$(this).val()'),



See the docs for more details: http://www.yiiframework.com/doc/api/1.1/CHtml#clientChange-detail.

Let us know it this solves the problem!


I follow this guide: http://www.yiiframework.com/wiki/164 and it work for me. Thankyou!