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在第一次搜索时工作,但在第二次搜索时重新加载页面 –