我加載一個視圖是控制器作用的結果:yii2加載一個觀點,即內容的形式進入模式
public function actionCreate()
{
$modelCreate = new CreateForm();
$user = User::findOne(Yii::$app->user->id);
$postes = $this->postes($user);
if (Yii::$app->request->isAjax && $modelCreate->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($modelCreate);
}
if ($modelCreate->load(Yii::$app->request->post()) && Yii::$app->request->isPost){
$modelCreate->photo = UploadedFile::getInstance($modelCreate, 'photo');
if ($modelCreate->create()){
return $this->redirect(['site/view-accounts']);
}
}
return $this->renderAjax('create-account', ['modelCreate' => $modelCreate, 'postes' => $postes]);
}
這裏是我的腳本加載的觀點:
$(function(){
$('#createModal').click(function(){
$('#newAccountModal').modal('show')
.find('#modalContentCreate')
.load($(this).attr('value'));
});
});
這裏是我的模態的代碼:
<?php
Modal::begin([
'id' => 'newAccountModal',
'header' => '<h4>create account</h4>',
]);
?>
<div id ="modalContentCreate">
</div>
<?php Modal::end();?>
但它的形式標記後插入的所有腳本,然後觸發一個錯誤:the xmlHttpRequest object is deprecated
...
而表單驗證的其他腳本沒有插入到主頁的主體的末尾。
如何才能觸發我的表單驗證並刪除此錯誤消息?
顯示你的表單代碼! –
我不明白你的頭銜。 – zhon