簡體   English   中英

在沒有活動表單的情況下從Yii2中保存select2下拉列表中的數據

[英]Saving data from select2 dropdown in Yii2 without active form

我有一個模態窗口,其中包含一個下拉菜單,詢問為什么某些東西被關閉的原因。

單擊“保存”,我希望在select2中選擇的信息像在活動表格中一樣更新模型...

這是模式窗口的代碼:

<div class="modal fade close-modal" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
              <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">Reason for closure</h4>
              </div>
            <div class="modal-body">
                <?php echo Select2::widget([
                    'model' => $model,
                    'attribute' => 'opportunity_closure_id',
                    'name' => 'closure-reason',
                    'options' => [
                        'limit' => 10,
                    ],
                    'addon'=> [
                    ],
                    'pluginOptions' => [
                        'allowClear' => true,
                        'ajax' => [
                            'url' => \Yii::$app->urlManager->createUrl('opportunity/closuredatalist'),
                            'dataType' => 'json',
                            'data' => new JsExpression($dataExp),
                            'results' => new JsExpression($dataResults),
                        ],
                        'initSelection' => new JsExpression($initScriptClosure),
                        'multiple' => false
                    ]
                ])?>            
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <?php echo \yii\helpers\Html::a('<span class=""></span> Save', ['opportunity/close','id' => $model->id], ['class' => 'btn btn-primary'])?>
            </div>
        </div>
    </div>
</div>

關於如何執行此操作的任何想法?

嘗試將type: "POST"添加到AJAX調用

我有下面的ajax電話工作,

        $.ajax({
        url: eduLevelCreateURL,
        cache: false,
        data: {"name":level.name,"shdesc":level.shdesc},
        type: "POST",
        timeout: 10000,
        dataType: "json",
        beforeSend: function (){
            $("#progresBarUpload").addClass("active");
            console.log(eduLevelCreateURL + " " + dataJ);
        },
        success: function (result) {
            console.log(result);
            var chtml = $("#person-educationid").html();
            chtml+=result.data;
            $("#person-educationid").html(chtml);
            $('#newCat').modal('hide');
            var value = result.value;
            $("#person-educationid option[value='" + value + "']").attr("selected", "selected");

        },

        error: function (msg) {
            alert("Error\n" + msg.toString());
        }
    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM