view:
// view 代码
$form = ActiveForm::begin(['id' => $model->formName()]); // js 代码
$js = <<<JS
$('form#{$model->formName()}').on('beforeSubmit', function(e) {
$.ajax({
url: $(this).attr('action'),
type: 'post',
data: $(this).serialize(),
success: function (data) {
if(data) {
$("#detail").modal('toggle');
location.reload();
}
}
});
}).on('submit', function(e){
e.preventDefault();
});
JS;
$this->registerJs($js);
controller:
// 主要是这句 return $this->renderAjax('/from', ['model' => $model]);
这里面我只是把最重要的部分记录了下来,其他的需要自己去思考。
针对这个,我最后的做法是太复杂了,直接在modal里面放个iframe来处理,当然也会遇到其他问题。