yii2 how to use pjax


Example

Add this line at the beginning of your view.

<?php
use yii\widgets\Pjax;
?>

Add the following two lines around the content that needs partial updating.

<?php Pjax::begin(['id'=>'id-pjax']); ?>
Content that needs to be updated
<?php Pjax::end(); ?>

reload pjax

$.pjax.reload({container: '#id-pjax'});

use timeout argument in pjax

<?php Pjax::begin(['id'=>'id-pjax', 'timeout' => false]); ?>

you can specify an integer value for the timeout argument, which would be the number of milliseconds to wait (its default value is 1000). If the execution time in the server is greater than this timeout value, a full page load will be triggered.

By default pjax will submit the form using GET method. You can change the form submission method to POST like in the following example

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