I am trying to use pjax to update some html on a page but the content loads in a new page instead of loading asynchronously.
View:
<?php Pjax::begin(['enablePushState'=>false]); ?>
<a href="/item/switch?id=1" data-pjax class="btn btn-success">Active</a>
<?php Pjax::end(); ?>
Controller:
public function actionSwitch($id)
{
$item = Item::findOne($id);
if ($item->active)
{
$item->active = 0;
$item->save();
return $this->render('_inactive_button', [
'item' => $item
]);
Yii::$app->end();
}
else
{
$item->active = 1;
$item->save();
return $this->render('_active_button', [
'item' => $item
]);
Yii::$app->end();
}
}
So the views rendered contain only the (anchor) button code. When I click the (anchor) button a new page is loaded with the layout and everything else instead of loading the button code via ajax.
Can anyone see what I’m doing wrong?