How To Update The Clistview After Deletion Of Record Using Ajax Request

here i am using the ajax request to delete the record from the clistview the record is deleting succesfully but the list view is not updating if we refresh the page then only the record is removing from the clist view can any one help here is my code

<?php

echo CHtml::link(CHtml::encode(‘Delete’), $this->createUrl(‘delete’, array(‘id’ => $data[‘id’])), array(// for htmlOptions

        'onclick' =&gt; ' {' . CHtml::ajax(array(


        'type'=&gt;'POST',


        'beforeSend' =&gt; 'js:function(){if(confirm(&quot;Are you sure you want to delete?&quot;))return true;else return false;}',


        'url'=&gt;&#036;this-&gt;createUrl('delete', array('id' =&gt; &#036;data['id'],'ajax'=&gt;'delete')),


        'complete'=&gt;'js:function(jqXHR, textStatus){&#036;.fn.yiiListView.update(&quot;firstlist&quot;);}'


        )) .


        'return false;}', // returning false prevents the default navigation to another url on a new page 


        )


    );

Dear Subash

views/post/index.php




<?php $this->widget('zii.widgets.CListView', array(

	'dataProvider'=>$dataProvider,

	'itemView'=>'_view',

	'id'=>"post_list",

)); ?>



I added the following part to _view.php.

views/post/_view.php




<?php echo CHtml::ajaxLink("Delete",array("post/delete","id"=>$data->id),array(


     "beforeSend" => 'js:function(){if(confirm("Are you sure you want to delete?"))return true;}',

     "success"=>'js:function(data){$.fn.yiiListView.update("post_list",{});}',

     "type"=>"post",


          ),array("id"=>$data->id)); ?>



This is working.

Regards.

It’s my first post here so “Hi everybody!” :)

My two cents to the topic: (according to seenivasan’s post#191773)

  1. Make sure, that id "post_list" is exactly the same in both files.

  2. Not so obvious. I suggest to change last line of views/post/_view.php to


),array("id"=>'delete_'.$data->id)); ?>

You need to be sure, that this is unique id in whole output document if it is supposed to be a valid html file. Moreover if you will have more ajax link, and you will use just


"id"=>$data->id

all of them will have the same id, and in consequence, all will be executing the same operation (probably of the last link in the document).

BTW why this topic is in Indian section? I thought that those international sections are for topics in foreign languages.