Yii Pagination With Ajax
I need to enable pagination with ajax my code Controller(update content ajax) function actionIndex(){ $dataProvider=new CActiveDataProvider('News', array( 'pa
Solution 1:
In your controller do this
if (Yii::app()->request->isAjaxRequest) {
$done =$this->renderPartial('index', array('dataProvider' =>
$dataProvider), true);
echo$done;
Yii::app()->end();
}
And change your ajax call to this
$.ajax({
url: 'index.php/news',
type: "POST",
dataType: "html",
success: function(data){
$('#news').html(data);
}
})
Solution 2:
@Let me see's answer is right also, but the second way is that you can use like that:
if (Yii::app()->request->isAjaxRequest) {
$done =$this->renderPartial('index', array('dataProvider' => $dataProvider), true);
echo CJSON::encode(array(
'status' => 'success',
'html' => $done,
));
Yii::app()->end();
}
$.ajax({
url: 'index.php/news',
type: "GET",
dataType: "JSON",
success: function(data){
$('#news').append(data.html);
}
});
It is right way to get a JSON
from server, or you want to get HTML
response use @Let me see's answer
Post a Comment for "Yii Pagination With Ajax"