如何在 yii2 中以模态 window 重新加载 pjax div

How to reload pjax div in modal window in yii2

我使用模态查看评论列表,模态有一个更新按钮和一个文本框。

当用户在文本框中输入一些文本并单击更新按钮时,我希望重新加载评论列表 div 而无需重新加载整个页面或关闭或隐藏模式。

我已经读过 阙。但仍然没有得到解决方案。

我的密码是

注册Js并查看文件

$this->registerJs("
$(function() {
    $('#replayMeg').on('beforeSubmit', function(event, jqXHR, settings) {
        var comment = $('#".Html::getInputId($modelReply, 'hdr_comments')."').val();
        var ticketId = $model->hdt_id;

        $.ajax({
            url: '".Url::to(['helpdesk-replies/create'])."',
            type: 'post',
            data: { replyMsg : comment, ticketId : ticketId},
            beforeSend: function() {
                if($('#".Html::getInputId($modelReply, 'hdr_comments')."').val() == '')
                {
                    $('.field-helpdeskreplies-hdr_comments').addClass('form-group field-helpdeskreplies-hdr_comments required has-error');
                    $('.help-block').html('Reply cannot be blank.');
                    return false;
                }
            },
            success: function(data) {
                //$.pjax.reload({container:'#update_replyBox'});
            }
        });

        return false;
    })
});
");

<?php yii\widgets\Pjax::begin(['id' => 'update_replyBox']); ?>
<div class="modal-body">
<div class="box-tools pull-right">
               <?= $actionBtn; ?>
            </div>
</div>
<div class="panel panel-info">
          <div class="panel-heading colorchangeheader left-align">
            <i class="fa fa-users fa-fw"></i> <?= $model->getUserName($cData['hdr_replay_user_id']); ?> <span class="mobilebreakpoint"><i class="fa fa-clock-o fa-fw"></i><?= Yii::$app->formatter->asDate($cData['created_at']); ?> @ <?= Yii::$app->formatter->asTime($cData['created_at']); ?></span>
          </div>
          <div id="rp8" class="panel-body">
           <?= $cData['hdr_comments'] ?>
          </div>
    </div>

<?php $form = ActiveForm::begin(['id' => 'replayMeg']); ?>
        <div class="box-body">
            <div class='row'>
                <div class='col-sm-12'>
                    <?= 
                        $form->field($modelReply, 'hdr_comments')->widget(RemainingCharacters::className(), [
                            'type' => RemainingCharacters::INPUT_TEXTAREA,
                            'name' => 'message_body',
                            'id' => 'message_body-textarea',
                            'text' => Yii::t('app', '{n} Characters Remaining'),
                            'label' => [
                                'tag' => 'p',
                                'id' => 'my-counter',
                                'class' => 'counter text-aqua',
                                'invalidClass' => 'error'
                            ],
                            'options' => [
                                'rows' => '3',
                                'class' => 'form-control replyTextArea',
                                'maxlength' => 200,
                                'placeholder' => Yii::t('app', 'Write something'),
                            ]
                        ]);
                    ?>
                </div>
            </div>
        <!--/div>
        <div class="box-footer"-->
            <?= Html::button('<i class="fa fa-reply"></i> '.Yii::t('comm', 'Reply'), ['class' => 'btn btn-info btn-create submit', 'type' => 'submit']) ?>
        </div>
        <?php ActiveForm::end(); ?>

    <?php yii\widgets\Pjax::end() ?>

请尝试在模态

中设置 backdrop false

'clientOptions' => ['backdrop' => false]

在您的活动表单中设置 data-pjax 为真

<?php $form = ActiveForm::begin(['options' => ['data-pjax' => true ]]); ?>

更多详情http://www.yiiframework.com/wiki/772/pjax-on-activeform-and-gridview-yii2/

有关模态的更多选项Refer