[英]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">×</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.