1
我似乎無法弄清楚爲什麼pjax會在第二個表單提交中重新加載頁面。它的工作原理與第一次提交表單時所提交的網址/site/profile?UserSearch%5Bsearchstring%5D=mi&_pjax=%23form-pjax
完全相同,然而,在第一個表單丟失網址/site/profile?UserSearch%5Bsearchstring%5D=m
的結尾之後。我檢查了實際的html代碼,表格保留了data-ajax
屬性。我嘗試增加超時,正如pjax重新加載整個頁面時所暗示的,但是這並沒有改變任何東西。Yii2 Pjax在第二個表單上重新加載整個頁面提交
下面的代碼是從我的觀點
<?php Pjax::begin(['timeout' => 5000, 'id' => 'form-pjax']); ?>
<?php $form = ActiveForm::begin([
'method' => 'get',
'action' => Url::to(['site/profile']),
'options' => ['data-pjax' => true ],
]); ?>
<?= $form->field($searchModel, 'searchstring', [
'template' => '<div class="input-group">{input}<span class="input-group-btn">' .
Html::submitButton('Search', ['class' => 'btn btn-default']) .
'</span></div>',
])->textInput(['placeholder' => 'Find friends by username or email']);
?>
<?php ActiveForm::end(); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
'username',
[
'label' => 'View Profile',
'format' => 'raw',
'value'=>function ($data) {
return Html::a(Html::encode("View Profile"),'/site/redirectprofile/'.$data->id);
},
],
[
'label' => 'Follow',
'format' => 'raw',
'value'=>function ($data) {
return Html::a(Html::encode(Follow::find()->where(['user_id' => $data->id, 'follower_id' => Yii::$app->user->Id])->exists() ? 'Unfollow' : 'Follow'),'/site/follow/'.$data->id.'/'.$data->username);
},
],
],
'summary'=>'',
]); ?>
<?php Pjax::end(); ?>
什麼代碼準確地將在裏面,我目前沒有任何代碼,使pjax –
我更新了你的答案。 –
不起作用,它具有相同的行爲。 pjax在第一次搜索時工作,但在第二次搜索時重新加載頁面 –