在MyajaxController
:
public function actionGetDropDownInfo(){
$selected_drop_down_val = $_POST['ddl']; // the drop down list's changed value
$article = "..."; // what you have to process with corresponding to $selected_drop_down_val
$drawing = "..."; // what you have to process with corresponding to $selected_drop_down_val
$variant = "..."; // what you have to process with corresponding to $selected_drop_down_val
echo json_encode(array(
'article' => $article,
'drawing' => $drawing,
'variant' => $variant
));
Yii::app()->end();
}
在你的窗体中添加的jQuery的一点:
<script>
$(function(){
$('#drop_down_list_id').on('change', function (e) {
//var optionSelected = $("option:selected", this);
var selectedValue = this.value;
$.ajax({
type: "POST",
url: "<?php echo Yii::app()->createUrl('Myajax/GetDropDownInfo')?>",
data: {ddl: selectedValue}, //post a selected value of drop down list
dataType: 'json',
beforeSend: function() {$('.loading-icon').show();},
complete: function() {$('.loading-icon').hide();},
success: function (data) {
// bind returned data into your fields
$('#article-field-id').val(data['article']);
$('#drawing-field-id').val(data['drawing']);
$('#variant-field-id').val(data['variant']);
}
});
});
</script>
以上是想法如何实现你的观点之一。我认为你的问题与Yii没什么关系,如果你用标签form
,jQuery
或ajax
进行搜索,你可以找到其他已经提出的解决方案。