私は登録ページを開発していますが、このページの一部は単独で提出する必要があります。私はいくつかの調査をして、yii2 utでPjaxを見つけましたが、ドキュメントで見つかったものは私のものと正しく動作しませんでした。私はyii2でウォーキングしないPjaxとフォーム提出
- タグが作成されません... csrfを含む隠し要素のみ。
- 提出すると、すべてのページが再読み込みされます。
ビュー:
<div class="row profileimg">
<?php Pjax::begin(['timeout' => 40000, 'id' => 'myPjax',]); ?>
<?= Html::beginForm(['couple-partner/saveprofileimg'], 'post', ['id' => 'CouplePartnerSumb', 'data-pjax' => true, 'class' => 'form-inline']); ?>
<div class="col-lg-12" onmouseover="onmouseOverImg('FirstPartnerEditButton', 'FirstPartnerDelButton');" onmouseout="onmouseoutImg('FirstPartnerEditButton', 'FirstPartnerDelButton')" id="imgdiv" style="display:inline-block;position: relative;left : 35%;height: 110px;width: 150px;">
<img src="<?= $models != NULL && sizeof($models) > 0 && $models[0]->USER_PROFILE_PIC != NULL ? $models[0]->USER_PROFILE_PIC : "" ?>" style="cursor: pointer;width:100%;height:100% " id="firstPartnerProfilePic" class="img-thumbnail ">
<?= Html::fileInput('imageFile', '') ?>
<?php echo Html::submitButton('Upload', ['class' => 'btn btn-primary', 'id' => 'submit_iddddd',]) ?>
</div>
<?php echo Html::endForm();Pjax::end();?>
</div>
コントローラ:私はPjaxが正常に動作しない問題が何であるかを見つけると、なぜクリックされたときにボタンがすべてのページをリロード提出することはできません
public function actionSaveprofileimg() {
$model = new CouplePartner();
if (Yii::$app->request->isAjax) {
$model->imageFile = UploadedFile::getInstance($model, 'imageFile');
if ($model->upload()) {
// file is uploaded successfully
return;
}
}
return $this->renderAjax('index', ['model' => $model]);
}
。
最初のチェック通常のポスト条件を処理している間に多くの問題をキャッチしてみてください) –