I have an viewing articles from databases and every article view with hole page load. So I would load articles without page reloading, I think this is possible using Ajax but I’m not so strong about it.
This is my initial concept like below:
Layout:
CHtml::link($menu['items'][$itemId]['label'],
array('articles/view',
'id'=>$menu['items'][$itemId]['link'],
)
);
// This showing articles name & link
View:
<?php
echo $model->article_body;
?>
<script>
jQuery.ajax({
type: 'POST',
dataType: 'html',
url: ('articles/view'),
success: function(data){
document.getElementById('articles').innerHTML = data;
},
error: function(){
alert('Somthing wrong');
}
});
</script>
Controller:
public function actionView($id)
{
$model=$this->loadModel($id);
$this->render('view',array('model' => $model));
}
Does someone can help me? Thanks