Hi, I’m trying to load some more content in a view by pressing a button. Pressing the button triggers an ajax listener calling an action supposed to be rendering some more content in the current view.
The ajax is successful but nothing is rendered in addition to the initial view (I also tried renderPartial but it does not work neither).
Here is the important content of the view :
<?php
$nextFlow = Url::to(['dashboard/fetch-flow-ajax', 'user' => $user->id, 'page' => $pageNumber]);
?>
<button class="testAjax">Test</button>
<?php
$this->registerJs("
jQuery(document).ready(function () {
$('.testAjax').on('click', function(){
$.ajax({
url: '$nextFlow',
type: 'POST',
success: function(){
Messenger().post({
message: 'flow loaded',
type: 'success',
hideAfter: 5,
hideOnNavigate: true,
});
}
})
})
});
")
?>
When clicking the button it triggers this action :
public function actionFetchFlowAjax($user, $page, $pageSize = self::PAGE_SIZE)
{
$comment = new Comment();
$data = $this->getFlowForUser($user, $page, $pageSize);
return $this->render('_items', [
'user' => $user,
'comment' => $comment,
'dataProvider' => $data,
]);
}
So this action get called successfully but nothing is rendered in the initial view despite using the render method.
In the ‘_items’ view I only put a <p>ok</p>
to test if the whole thing works and previously it had more complex content. But it is not rendered either way.
If you have any clue on why it does not work, I thank you in advance.