Search code examples
postyii2pjax

Pjax in Yii 2 with POST request


How can I use Pjax in Yii 2 with POST request?

I tried to do it like that but page restarts anyway:

<?php Pjax::begin(['id' => 'some-id', 'clientOptions' => ['method' => 'POST']]);?>

 ...
 some content
 ...

<?=Html::a('', ['cart/cart'],
               ['class'=>'close1',
                    'data' => [
                        'method' => 'post',
                        'params' => [
                            'idCartToDelete' => $product->idCart,
                         ],
                    ]
                ]
          )
?>

 ...
 some content
 ...

<?php Pjax::end(); ?>

Solution

  • You're close to solving your issue. To your Html::a parameters add:

    'data-pjax' => 0,
    

    And you will have a link that does not redirect to another page.