Answer the question
In order to leave comments, you need to log in
Yii2. How to create url in js files?
How to create url in js files?
so it creates links like this www.example.com/post?id=1
$.ajax({
url: base_url + '/post/',
dataType: "json",
data: {'id': id},
success: function (response) {
...
}
});
$.ajax({
url: base_url + '/post/' + id,
dataType: "json",
success: function (response) {
...
}
});
Answer the question
In order to leave comments, you need to log in
it is possible to transfer url from php to js
through registerScript . And then in js to replace the necessary parts.
PHP:
$js = 'var myUrl = "' . Yii::app()->createUrl('bla/bla/bla', array('id' => 'REPLACE_HERE')) . '";';
Yii::app()->getClientScript()->registerScript('carramba', $js, CClientScript::POS_HEAD )
var realUrl = myUrl.replace('REPLACE_HERE', id);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question