ajax reload problem

here is the problem: When i do the login with the credentials that i gave to you, and then try to make the logout without refreshing the page, the ajax function does not refresh to the new button id, and when you make a logout and try to login right away, the submit button works like a submit button and not like an ajax submit button.

you can test it here:

ht tp:// teste.qiteam.org </p>

login -> 123@123.com</p>

pass -> testing

here is the code:


// Code at this moment.

    

    // Login View

    

    <?php

        if (!isset($model))

                $model = new LoginForm;

    

                echo "<h3>Login</h3>";

    

                echo CHtml::beginForm('login');

    

                echo CHtml::errorSummary($model);

    

                echo"<div class='row'>";

                echo CHtml::activeLabel($model,'username');

                echo CHtml::activeTextField($model,'username');

                echo"</div>

    

                        <div class='row'>";

                echo CHtml::activeLabel($model,'password');

                echo CHtml::activePasswordField($model,'password');

                echo "</div>

    

                        <div class='row'>";

                echo CHtml::activeCheckBox($model,'rememberMe');

                echo CHtml::activeLabel($model,'rememberMe');

                echo "</div>

    

                        <div class='row submit'>";

                echo CHtml::ajaxSubmitButton('Login',array('/login'),array('update' => '#panel_contents'),array('live'=>false));

                echo "</div>";

    

                echo CHtml::endForm();

    ?>

    

    // Index Panel Widget

    

    class index extends CWidget

    	{

    		public function run()

    		{

    			if ( Yii::app()->user->isGuest)

    				$this->render('login');

    			else

    			{

    				$username = Yii::app()->user->firstname . " " . Yii::app()->user->lastname;

    				echo " <h3> Hi, $username " ;

                                    echo CHtml::ajaxLink('Logout',array('/logout'),array('update' => '#panel_contents'),array('live'=>false,'id'=>'logoutLink'));

    				echo "</h3>";

    			}

    		}

    	}

    

    // Login Action

    

    $model = new LoginForm;

    		if (isset($_POST['LoginForm']))

    		{

    			$model->attributes=$_POST['LoginForm'];

    			

    			if ($model->validate())

    				$this->renderPartial('update');

    		}

    		else

    		{

    			$this->renderPartial('update');

    		}

    // logout Action


    public function actionLogout()

	{

		Yii::app()->user->logout();

                $this->renderPartial('update');

	}




// update view

    

    <?php

    	$this->widget('application.extensions.panel.index')

    ?>

Thank you

I tried and seems that even logout process doesn’t work correctly(doesn’t logout me). Can you paste here logout function too?

it does logout, the only thing is that, if you try to do that instantly after login it does’nt work.

Updated first post

Any1 with more ideas?

Solved.

Seems that the ajax functions are inserted into the page, with the layout, and when we refresh a div and inside that div we have a different ajaxlink button, it will not refresh the ajx function.

So, the Solution is adding a custom ajax function in every view, like this:

Logout View




<?php

    echo " <h3> Hi, $user";

    echo CHtml::ajaxLink('Logout', array('/logout'), array('update' => '#panel_contents'), array('live' => false, 'id' => 'AjaxLogout'));

    //echo CHtml::link('Logout',array('id' => 'AjaxLogout'));

    echo "</h3>";

    

    

?>


    <script type="text/javascript">

        jQuery('#AjaxLogout').unbind('click').bind('click', function(){jQuery.ajax({'type':'POST','url':'/logout','cache':false,'data':jQuery(this).parents("form").serialize(),'success':function(html){jQuery("#panel_contents").html(html)}});return false;});

    </script>

Login View


<?php

    ...


            echo "<h3>Login</h3>";


            echo CHtml::beginForm('login');


            echo CHtml::errorSummary($model);


            echo"<div class='row'>";

            echo CHtml::activeLabel($model,'username');

            echo CHtml::activeTextField($model,'username');

            echo"</div>


                    <div class='row'>";

            echo CHtml::activeLabel($model,'password');

            echo CHtml::activePasswordField($model,'password');

            echo "</div>


                    <div class='row'>";

            echo CHtml::activeCheckBox($model,'rememberMe');

            echo CHtml::activeLabel($model,'rememberMe');

            echo "</div>


                    <div class='row submit'>";

            echo CHtml::ajaxSubmitButton('Login',array('/login'),array('update' => '#panel_contents'),array('live'=>false,'id'=>'AjaxLogin'));

            //echo CHtml::submitButton('Login',array('id' => 'AjaxLogin'));

            echo "</div>";


            echo CHtml::endForm();

?>


    <script type="text/javascript">

        jQuery('#AjaxLogin').unbind('click').bind('click', function(){jQuery.ajax({'type':'POST','url':'/login','cache':false,'data':jQuery(this).parents("form").serialize(),'success':function(html){jQuery("#panel_contents").html(html)}});return false;});

    </script>