Add Item With Ajax (Renderpartial)

Hey

I want to add a new Item with AJAX with renderPartial but it doesn’t work. Thx for help

My CODE (short form):

Controller (AJAX)




public function actionCreatedestination($id)

	{       

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

          $destination = new Destination;  

          $destination->attributes = $_POST['Destination'];

          $trip->addDestination($destination);  

          }

          

          $this->renderPartial('_view', array(

	            'model'=>$trip,

                    'destination'=> $destination,

                    false,

                true

            ));

       } 



view:





echo CHtml::ajaxSubmitButton('Add', array('trip/createdestination', 'id' => $id), array(

        'type' => 'post', 

        ),

        array('id' => 'addDestination')); 


$this->renderPartial('_view', array(

        'model'=>$model,

        'destination'=> $destination,

    ));



_view:




<?php foreach($model->destinations as $i => $destination) { ?>

<?php echo $destination->id; ?>

<?php } ?>



You do a ajax request, but you do nothing with the result.

You need to add the html yourself:


CHtml::ajaxSubmitButton(

        'Add', 

        array('trip/createdestination', 'id' => $id), 

        array(

          'type' => 'post', 

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

            if(result != "") {

              $("#partial-data").append( result ); //add to partial-data

            }

          }'

        ),

        array(

          'id' => 'addDestination'

        )

); 


<div id="partial-data">

$this->renderPartial('_view', array(

        'model'=>$model,

        'destination'=> $destination,

    ));

</div>

This is not tested, but it should work something like this.