how to have an ajax callback on dropdownlist

Hi,

I have a dependent dropdown which I fill through ajax. I want to call a function after ajax is done. Any ideas?


echo Chtml::dropDownList('optAudioSura', $strAudioSuraTemp, $suraOptions,

                                array(

                                    'ajax' => array(

                                        'type'=>'POST', //request type

                                        'url'=>CController::createUrl('QuText/audioFiles'), //url to call.

                                        'update'=>'#optAudio', 

                                        'data'=>'js:jQuery(this).serialize()',

                                        )

                                    ));  

Thanks

Hello

You’ll have to use the ‘success’ property of the ajax method. A minor downside is that you can’t combine it with the ‘update’ one.

However, it’s easy to combine both with the ‘success’ one (remember that ‘update’ is just a shortcut anyway), like this:


echo Chtml::dropDownList('optAudioSura', $strAudioSuraTemp, $suraOptions,

                                array(

                                    'ajax' => array(

                                        'type'=>'POST', //request type

                                        'url'=>CController::createUrl('QuText/audioFiles'), //url to call.

                                        //'update'=>'#optAudio', 

                                        'data'=>'js:jQuery(this).serialize()',

                                        'success'=>'js:function(data) {

                                            // Here you call what you want upon success

                                            // …

                                            $("#optAudio").html(data); // equivalent to you 'update' property

                                        }'

                                        )

                                    ));