In salary form I want to get data from ratechart model in certain textfields when the form loads.
In Ratechart Controller I've added
public $rateid = '1';
public function actionGetForRatechart($rateid)
{
$rates = Ratechart::find()->where(['rc_id'=> $rateid])->asArray()->one();
echo Json::encode($rates);
}
In salary _form I've added the following javascript code -
<?php
$script = <<<EOD
$(window).load(function(){
$.get('index.php?r=salary/ratechart/get-for-ratechart',{ rateid : rateid }, function(data){
alert(data);
var data = $.parseJSON(data);
});
EOD;
?>
It's not giving any result. It's the same question as Load data to a form from a different model in yii2. Please help.