How To Use Ajax When Clicking A Dropdown

i want my notification to be set 0 when the dropdown is clicked. after clicking dropdown, the value in <span id="notif"> must also change into 0.

script below is my progress so far. debugging by using chrome, i found error message "Uncought SyntaxError : Unexpected Token }".

please help if any of you know how to solve this problem. thank you :)

this view inside theme folder

<li class="dropdown" style="text-align: left" 

    onclick="   <?php

                    echo CHtml::ajax(array(

                        'id' =>'updatestatus',

                        'type' => 'POST',

                        'url' => Yii::app()->createUrl('tx/notification/updatestatus'),

                        'update' => '#notif',




    <a href="#" data-toggle="dropdown" class="dropdown-toggle"  >

        <span class="glyphicon glyphicon-bell"></span> 

        <span id="notif" class="badge">


            echo $unreadNotif;



        <b class="caret"></b>





notification controller



        public function filters() { 

            return array( 'rights', ); 


        public function allowedActions() { 

            return 'UpdateStatus';    


        public function actionUpdateStatus(){


                $notifications = Notification::model()->findAllByAttributes(array('read_status'=>false,'notify_to'=>Yii::app()->user->id));

                foreach ($notifications as $notify) {




                echo '0';     






I tried your code above and followed your steps meticulously but it seems there is something wrong.Have you tested your code?

It’s a jquery error. for more help please try this -

Also may be this will help you -

try this

<?php   Yii::app()->clientScript->registerScript(



            type: 'POST',

            url: '".$url."',

            success: function(html){






  ); ?>

actually my code was correct, but since i put the ajax inside html tag, the JQuery generated by Yii got mixed with the quatation mark ( " " ) of html inside onclick. with a little trick, the code is working fine now.

             	$ajax = CHtml::ajax(array(

                                        'type' => 'POST',

                                        'url' => Yii::app()->createUrl('tx/notification/updatestatus'),

                                        'update' => '#notif'


                $ajax = str_replace('"', "'", $ajax);

		<li class="dropdown" style="text-align: left" onclick ="<?php echo $ajax; ?>" >

thank you for all your answer. :)