How Can I Update An Div With Ajax?

I have a little problem about, when I try to update (refresh) my div’s content, the Ajax replace the all page in that div.

Here the problem: Screenshoot of the problem

Here is my controller source:How should it looks


public function actionView() {

        //print_r($_POST);

        $model = null;


        if( "user" == Yii::app()->user->getState("user_type")){

            $model = new FormResultUser();

        }

        else if( "faction" == Yii::app()->user->getState("user_type")){

            $model = new FormResultFaction();

        }


        $index = 0;

        //echo $index;

        if( Yii::app()->request->isAjaxRequest){

            if(isset($_POST['index'])){

                $index = CPropertyValue::ensureInteger( $_POST['index'] ) +1;

            }

        }

        //echo $index;

        $criteria = new CDbCriteria();

        $criteria->limit = "1";

        $criteria->offset = $index;

        $questionModel = Question::model()->find($criteria);


       // print_r($questionModel);


        if (Yii::app()->request->isAjaxRequest) {

            $this->render('_viewForm', array('model' => $model, 'questionModel'=> $questionModel, 'index'=>$index));

        } else {

            $this->render('viewForm', array('model' => $model, 'questionModel'=> $questionModel, 'index'=>$index));

        }       

    }

And my viewForm: Here you can see, the AjaxSubmitButton is here. and <div id="form"> is too, what I would like to update. ( and I would like to update the $index variable too in the ajaxSubmitButton)

I tired the ‘replace’ too, but it doesn’t work well, the problem is the same.




<?php /* FormFilling */ ?>

<div id="form">

    <?php $form=$this->beginWidget('CActiveForm'); ?>


    <?php

    $this->renderPartial('_viewForm', array('model' => $model, 'questionModel'=> $questionModel, 'index'=>$index, 'form'=>$form));

    ?>

    <div class="row margin10">


    <?php

    echo CHtml::ajaxSubmitButton(Yii::t('strings', 'Next'), Yii::app()->createUrl('formFilling/view'), array(

            'type' => 'post',

            'data' => array("index" => $index),

            'update' => '#form',

        ));

    ?>

    </div>

    <?php $this->endWidget(); ?>

</div><!-- end form -->



At finally my _viewForm:


<?php

$answers = CHtml::listData(Answer::model()->findAll(), 'value', 'label');

?>

<div id="formAnswer" class="row"></div>

<div class="row text">

    <p>

        <?php echo CHtml::encode($questionModel->text); ?>  

    </p>        

</div>

<div class="row margin10">

    <span>

        <?php echo CHtml::encode(Yii::t('strings', 'Answer options'), ''); ?>

    </span>

    <div class="margin10">

        <?php

        echo CHtml::activeRadioButtonList($model, 'answer_value', $answers, array("class" => "left"));

        ?>   

    </div>    

</div>

<div class="row margin10">

    <span>

        <?php echo CHtml::label(Yii::t('strings', 'Significant topic'), 'ch_answer_important'); ?>

    </span>


    <?php

        echo CHtml::activeCheckBox( $model,

                                    'answer_important',

                                    array("id" => "ch_answer_important", "class" => "left"));

    ?>   


</div>

<?php //echo CHtml::hiddenField('index', $index) ?>




if (Yii::app()->request->isAjaxRequest) {

    $this->renderPartial('_viewForm', array('model' => $model, 'questionModel'=> $questionModel, 'index'=>$index), false, true);



Did you forget renderPartial() for ajax request?

Yes, you are right, thanks :).