Hi,
I am using the Yii2 basic. Until now I was using default URL format in the application. I have a Church CRUD and on the _form.php I was having the following code. It was working fine.
<?= $form->field($model, 'DistrictId')->dropDownList(ArrayHelper::map(District::find()->all(),'DistrictId','District'), ['prompt' => 'Select District','onChange' => '
$.post("index.php?r=taluka/lists&id=' . '"+$(this).val(),function(data){
$("select#church-talukaid").prop("disabled",false);
$("select#church-talukaid").html(data);
});
'
])?>
Now I am using a pretty URL for my application. So I am using Url::to() method to create a route.
So I changed the above code to the following, which is not working
<?= $form->field($model, 'DistrictId')->dropDownList(ArrayHelper::map(District::find()->all(),'DistrictId','District'), ['prompt' => 'Select District','onChange' => '
$.post("<?php echo \yii\helpers\Url::to([taluka/lists, id=>$(this).val()])?>" ,function(data){
$("select#church-talukaid").prop("disabled",false);
$("select#church-talukaid").html(data);
});
'
])?>
How can I use Url::to() in $.post() method correctly?