Answer the question
In order to leave comments, you need to log in
Yii2. How to generate url in javascript code?
when I specify the url manually, it works on the main page,
but on others, instead of sending a request without reloading, it goes to the specified url
<?php $js = <<<JS
jQuery('#forgot-password').on('click', function(){
jQuery.post('site/request-password-reset')
.done(function(result) {
....
})
return false;
})
JS;
$this->registerJs($js);
?>
Answer the question
In order to leave comments, you need to log in
Decided by adding to the layout
<script>
var base_url = '<?= \Yii::$app->request->hostInfo . "/" . \Yii::$app->language; ?>';
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question