Strance
(Shahrulhadi)
March 22, 2016, 8:13am
1
Hi, i want to use pjax.
I do just as the documentation explain
use yii\widgets\Pjax;
Pjax::begin();
echo GridView::widget([...]);
Pjax::end();
I also try example in this tutorial.
Both of them result in page loading. So why pjax doesnt work for me?
Hi!
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…
Regards
Strance
(Shahrulhadi)
March 23, 2016, 1:02am
3
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
<?php
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]); ?>
<p>
<?= Html::a(Yii::t('app', 'Create Position'), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php
Pjax::begin();
echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'nama',
'skop',
'kod',
'turutan',
[
'attribute' => 'createdByUser',
'value' => 'createdBy.username',
'label' => 'Created By'
],
// 'created_at',
// 'updated_by',
// 'updated_at',
['class' => 'yii\grid\ActionColumn'],
],
]);
Pjax::end();
?>
</div>
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.
Hi!
Strance:
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:
Pjax::begin([
'timeout' => false,
'enablePushState' => false,
]);
And please try again…
Regards
Strance
(Shahrulhadi)
March 23, 2016, 9:15am
5
MetaCrawler:
Hi!
Regarding Firebug:
In Firebug is somewhere a button called "persistent" or "durable" or something like that.
When you press it you will see 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:
Pjax::begin([
'timeout' => false,
'enablePushState' => false,
]);
And please try again…
Regards
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
So what is this pjax timeout issue? Is it ok to left it like that, or is there something i should fix?
Hey,
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.
Pjax::begin([
'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…
Regards
Strance
(Shahrulhadi)
March 24, 2016, 2:24am
7
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);
});
JS;
$this->registerJs($script);
?>
<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(); ?>
Strance
(Shahrulhadi)
March 24, 2016, 3:07am
8
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