Fedor Filippov
Fedor Filippov

Reputation: 71

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(); ?>

Upvotes: 3

Views: 3107

Answers (1)

Gynteniuxas
Gynteniuxas

Reputation: 7103

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.

Upvotes: 2

Related Questions