Answer the question
In order to leave comments, you need to log in
How to specify the path to the action in Yii in a JS file?
Hello. Is it possible to specify the path to the Action in the JS file at all?
$('.who').bind("change keyup input click", function() {
if (this.value.length >= 2) {
$.ajax({
type: 'post',
url: "<?= $this->createUrl('city/City')?>", //Путь к обработчику
data: { 'referal': this.value },
response: 'text',
success: function(data) {
$(".search_result").html(data).fadeIn();
}
})
}
})
Answer the question
In order to leave comments, you need to log in
It would be more correct to either pass the url through the data attribute and get it in js through something like $(this).data('url'), or pass the url to the script at the time of initialization, for example, through the $.widget options.
Either specify a direct path to the handler, or in php pass it to js through a variable
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question