P
P
Petr Fronin2016-03-12 09:38:29
Yii
Petr Fronin, 2016-03-12 09:38:29

How to pass variable from PHP to JavaScript in Yii2?

How to pass variable from PHP to JavaScript in Yii2?
Example:

$qwe = 'Вася';

$script = <<< JS
    $.ajax({
      type: 'GET',
      url: '............',
      data: { id: !!!!!! сюда вставить $qwe !!!!!!!},
    });
JS;
$this->registerJs($script, yii\web\View::POS_READY);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Bukharev, 2016-03-12
@amar_std

$qwe = 'Вася';

$script = "
    $.ajax({
      type: 'GET',
      url: '............',
      data: { id: ".$qwe ."},
    });
";
$this->registerJs($script, yii\web\View::POS_READY);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question