title: Ajax update content in yii
body: <p>I have an issue with the ajax, which doesn't update the content which is saved. The data are saving fine in the database. It only shows when I refresh the page.
  The code for echo the comments  </p>
  
  <pre><code>&lt;?php
  echo '&lt;div&gt;&lt;h3&gt;&lt;b&gt;&lt;u&gt;Comments&lt;/u&gt;&lt;/b&gt;&lt;/h3&gt;&lt;/div&gt;';
  $commentList = Comments::model()-&gt;findAllByAttributes(array('offereventid'=&gt;$id));
  foreach($commentList as $Listdata2)
  {   
      $usercomment = $Listdata2['comment']; 
      $usercommentid = $Listdata2['id']; 
      $usercomtname = $Listdata2['name'];
      $usercommentmail = $Listdata2['email'];
      echo '&lt;div id = "name_'.$usercommentid.'"&gt;';
      echo '&lt;div&gt;&lt;span class="name1"  &gt;'.$usercomtname.':&lt;/span&gt; '.'&lt;span class ="email1"&gt;'.'['.$usercommentmail.']'.'&lt;/span&gt;'.'&lt;/div&gt;';
      echo '&lt;div class = "cmnts"&gt;'.'"'.$usercomment.'"'.'&lt;/div&gt;';
      if (Yii::app()-&gt;user-&gt;id!='' &amp;&amp; Yii::app()-&gt;user-&gt;id!=1){
          if(Yii::app()-&gt;user-&gt;email==$usercommentmail){
             echo CHtml::ajaxButton('Delete',CHtml::normalizeUrl(array('Comments/del/id/'.$usercommentid,'render'=&gt;true)),
                  array(
                    'dataType'=&gt;'json',
                    'type'=&gt;'post',
                    'success'=&gt;'function(data){
                       alert("Are You Sure?");
                       $("#name_"+data).hide();
                     }',
                  ),array('id'=&gt;$usercommentid,'class'=&gt;'btn btn-danger'));
  
            }  
        }
       echo '&lt;hr&gt;&lt;/div&gt;';
  
  } 
  ?&gt;  
  </code></pre>
  
  <p>here you can see I  used ajax delete button which works fine.<br>
  Below the code is used to save the comment into the database  </p>
  
  <pre><code>&lt;?php
      echo CHtml::ajaxSubmitButton('Save',CHtml::normalizeUrl(array('Comments/create','render'=&gt;true)),
          array(
              'dataType'=&gt;'json',
              'type'=&gt;'post',
              'success'=&gt;'function(data){
                  $("#AjaxLoader").hide();
                  if(data.status == "success"){
                    $("#formResult").html("Comment Submitted");
                    $("#formResult").css({"color":"red"});
                    $("#comments-form")[0].reset();
                   }else{
                     $.each(data, function(key, val){
                     $("#comments-form #"+key+"_em_").text(val);
                     $("#comments-form #"+key+"_em_").show();
               });
                  }
              }',
              'beforeSend'=&gt;'function(){
              $("#AjaxLoader").show();
              }'
              ),array('id'=&gt;'submit'.uniqid(),'class'=&gt;'btn btn-success'));
  
  ?&gt;
  </code></pre>
  
  <p>And the <strong>actioncreate</strong> is  </p>
  
  <pre><code>public function actionCreate()
  {
      $model=new Comments;
  
      // Uncomment the following line if AJAX validation is needed
      $this-&gt;performAjaxValidation($model);
  
      if(isset($_POST['Comments']))
      {
          $model-&gt;attributes=$_POST['Comments'];
          // echo '&lt;pre&gt;';print_r($model-&gt;attributes);die();
          $valid = $model-&gt;validate();
  
          if($valid){
              if($model-&gt;save()){
              echo CJSON::encode(array(
                  'status'=&gt;'success'
                  ));
          }
          }else{
              $error =CActiveForm::validate($model);
              if($error != '[]')
                  echo $error;
              Yii::app()-&gt;end();
          }
      }
      // $this-&gt;render('create',array(
      //  'model'=&gt;$model,
      // ));
  }
  </code></pre>