i want to delete an item of clistview via ajax button. it works in the first page, but not other pages. Could somebody please help me?
controller
public function actionIndex() {
$criteria = new CDbCriteria(array(
'order' => 'create_at DESC',
));
$dataProvider = new CActiveDataProvider('Note', array(
'pagination' => array(
'pageSize' => 10,
),
'criteria' => $criteria,
));
$this->render('index', array(
'model' => $model,
'dataProvider' => $dataProvider,
));
}
view: index
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'summaryText'=>'',
'id'=>'note-list',
));
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/js/jquery.confirm.js');
Yii::app()->clientScript->registerScript('note-delete-js', "
$(document).ready(function() {
$('#note-list .delete').click(function() {
var elem = $(this).closest('.post');
$.ajax({
type: 'POST',
url: '/xxx/index.php/note/delete/'.concat($(this).next().val()),
});
elem.slideUp();
return false;
});
$('#note-list .delete').confirm({
msg:'Do you really want to delete this Note?',
timeout:3000
});
});
");
view: _view
<div class="post">
<div class="content">
<?php echo GxHtml::encode($data->content); ?>
</div>
<div>
<a class="btn delete">Delete</a>
<input type="hidden" value="<?php echo $data->id;?>">
</div>
</div>