Disable pjax loading on certain buttons inside Pjax container (Yii2)

Vipul picture Vipul · Nov 12, 2016 · Viewed 9.3k times · Source

I need to disable pjax inside pjax container on some anchor tags like cancel/ back button. Below is my code:

Pjax::begin(['id' => 'pjax-container-pac-form','timeout' => 10000, 'enablePushState' => false]);
$form = ActiveForm::begin([
'options' => [
    'id' => 'create-pac-form',
    'data-pjax' => true
]
]);
echo Html::a(Yii::t('app','Cancel'), ['/agency'], ['class' => 'btn btn-default', 'id' => 'cancelButton', 'data-pjax' => false]);
ActiveForm::end();
Pjax::end();

I tried to add 'data-pjax' => false on anchor tag but it's not working. Although it's redirecing back to specified url but at first it's trying to hit via ajax and after that it redirects back to the link. I would like to disable ajax here and redirect it back to the url being specified. I can do so by moving the cancel button out of pjax container but I'm looking for some better way of doing it without modifying HTML at all.

Answer

Mohan picture Mohan · Nov 12, 2016

Replace 'data-pjax' => false with 'data-pjax' => 0 in anchor tag