Yii2如何调用post函数

Yii2如何调用post函数,post,yii2,Post,Yii2,在Yii2表单中,当某个字段发生变化时,我需要触发一些代码 我用onchange来做这个 这就是我需要的东西: ->dropDownList(Customer::getDataList(), [ 'prompt' => Yii::t('app','select.customer'), 'onchange' => '$.post("index.php?r=comptacust/selectedlists&id='.'"+$(this).val(), fu

在Yii2表单中,当某个字段发生变化时,我需要触发一些代码 我用onchange来做这个

这就是我需要的东西:

->dropDownList(Customer::getDataList(), [
    'prompt' => Yii::t('app','select.customer'), 
    'onchange' => '$.post("index.php?r=comptacust/selectedlists&id='.'"+$(this).val(), function(data) {
        $("select#invoiceheader-comptacust_id").html(data);
    })', 
    'onchange' => '$.post("index.php?r=pmtmode/selectedlists&id='.'"+$(this).val(), function(data) {
        $("select#invoiceheader-pmtmode_id").html(data);
    })', 
    'onchange' => '$.post("index.php?r=pmtcondition/selectedlists&id='.'"+$(this).val(), function(data) {
        $("select#invoiceheader-pmtcondition_id").html(data);
    })',
]);
但是post功能只工作1次(对于PMT条件)

我需要做什么才能完成这3篇文章


任何帮助都很好:)

您所做的只是在
下拉列表中替换
onchange
值,因此您需要在一个
onchange
赋值中添加js代码:

->dropDownList(Customer::getDataList(), [
    'prompt' => Yii::t('app','select.customer'), 
    'onchange' => '
        $.post("index.php?r=comptacust/selectedlists&id='.'"+$(this).val(), function(data) {
            $("select#invoiceheader-comptacust_id").html(data);
        });
        $.post("index.php?r=pmtmode/selectedlists&id='.'"+$(this).val(), function(data) {
            $("select#invoiceheader-pmtmode_id").html(data);
        });
        $.post("index.php?r=pmtcondition/selectedlists&id='.'"+$(this).val(), function(data) {
            $("select#invoiceheader-pmtcondition_id").html(data);
        });
    ',
]);