I’m trying to create Dependent Drop down lists. But onchange I get a 404 error in the inspect element console
http://paie.loc/index.php?r=newtest%2Flist_fid%3Fid%3D1 404.
If I go to index.php?r=newtest%2Flist_fid&id=7 I get the desired list.
My problem is getting the url to the navigator that works to fill the dependent dropdown correctly.
Localhost server Apache2 on Linux Mint (Ubuntu).
AllowEncodedSlashes On in apache2.conf and virtualhost.
Fails on Firefox and Opera both
newtest/
_form
<?= $form->field($model, 'gfID')->dropDownList(
Grandefonction::dropdown(),
[
'style'=>'width:300px',
'prompt'=> 'Grande Fonction',
'onchange'=>'$.post("'.Yii::$app->urlManager->createUrl('newtest/list_fid?id=').'"+$(this).val(), function(data) {
$( "select#fID" ).html(data);}
);'
]
) ;?>
<?= $form->field($model, 'fID')->dropDownList(Fonctions::dropdown(), ['prompt' => 'Fonction','style'=>'width:300px', 'id'=>'fID']); ?> <?= $form->field($model, 'sfID')->dropDownList(Sousfonction::dropdown(), ['prompt' => 'Sous Fonction','style'=>'width:300px']) ?>NewtestController
public function actionList_fid($id)
{
$countfonctions = Fonctions::find()->where([‘gfID’=>$id])->count();
$fID = Fonctions::find()->where([‘gfID’=>$id])->orderBy(‘id’)->all();
if ($countfonctions > 0) {
foreach ($fID as $result) {
echo “”.$result->name."";
}
} else {
echo “-”;
}
}
Fonctions Model
public static function dropdown()
{
static $dropdown;
if ($dropdown === null) {
$models = static::find()->all();
foreach ($models as $model) {
$dropdown[$model->id ] = $model->name;
}
}
return $dropdown;
}