pjax doesnt work for me

Hi, i want to use pjax.

I do just as the documentation explain

use yii\widgets\Pjax;


echo GridView::widget([...]);


I also try example in this tutorial.

Both of them result in page loading. So why pjax doesnt work for me?


Have you installed Firebug?

If not I would suggest installing it and check for errors there.

Also it would be helpful if you would share more of your code to track down your problem…


my controller actionIndex

public function actionIndex()


        $searchModel = new JawatanSearch();

        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        return $this->render('index', [

            'searchModel' => $searchModel,

            'dataProvider' => $dataProvider,



my view index


use yii\helpers\Html;

use yii\grid\GridView;

use yii\widgets\Pjax;

/* @var $this yii\web\View */

/* @var $searchModel app\models\JawatanSearch */

/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Positions');

$this->params['breadcrumbs'][] = $this->title;


<div class="jawatan-index">

    <h1><?= Html::encode($this->title) ?></h1>

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>


        <?= Html::a(Yii::t('app', 'Create Position'), ['create'], ['class' => 'btn btn-success']) ?>




    echo GridView::widget([

        'dataProvider' => $dataProvider,

        'filterModel' => $searchModel,

        'columns' => [

            ['class' => 'yii\grid\SerialColumn'],







                'attribute' => 'createdByUser',

                'value' => 'createdBy.username',

                'label' => 'Created By'


            // 'created_at',

            // 'updated_by',

            // 'updated_at',

            ['class' => 'yii\grid\ActionColumn'],






looking at firebug net tab, i did see pjax aborted for a second, but then the message disappear, so i cant get to see the details.


Regarding Firebug:

In Firebug is somewhere a button called "persistent" or "durable" or something like that.

When you press it you wil still see the error in Firebug even after page-reload. ;)

Regarding your Problem:

Maybe you face a Pjax Timeout issue.

Change your Pjax begin like this:


   'timeout' => false,

   'enablePushState' => false,


And please try again…


Yes it work now, no loading anymore. But it doesnt change the browser url. I thought pjax was mean to do that as well?

With persistent button activate, i can see the error now. But i dont has any idea what it is about :lol:

So what is this pjax timeout issue? Is it ok to left it like that, or is there something i should fix?


What is changing the URL is called "PushState".

You could enable it again…

But I don’t think you will have much URL change when you only update a gridview rather than a complete site.


   'timeout' => false,

   // 'enablePushState' => false,


Regarding the timeout:

The Pjax Widget is basically "waiting for an answer" in a specific timeframe.

If the answer takes longer than expected,

the whole page will be reloaded instead of the Pjax container.

So we just disabled the timeout with:

"timeout" => false 

To get better understanding just google "Pjax Timeout" or "Ajax timeout" and just read some pages about AJAX / PJAX…


Thx for the explination.

Today i try this tutorial again.

The first step refreshing the time out put by clicking on the button work.

But the second step adding a javascript code to do autorefresh doesnt work and also causing manually press the button also doesnt work.

So i take a look at firebug. It show there is request for pjax each second i believe doen by the auto refresh script but they are all aborted. Any idea why?.

use yii\widgets\Pjax;

use yii\helpers\Html;

$script = <<< JS

$(document).ready(function() {

    setInterval(function(){ $("#refreshButton").click(); }, 1000);





<h1>Pjax demo in action, be alert!!</h1>

<?php Pjax::begin([

  'timeout' => false,

  'enablePushState' => false,

]); ?>

<?= Html::a("Refresh", ['site/pjax'], ['class' => 'btn btn-lg btn-primary', 'id' => 'refreshButton']) ?>

<h1>Current time: <?= $time ?></h1>

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

sorry for the question above, it aborted becuase i set interval 1000ms. 3000ms like in the tutorial will be ok. I guess it doesnt has enough time before new request being send when interval is set to 1000ms