50
37

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScriptでPHPの変数の値を使う方法メモ

Last updated at Posted at 2015-08-26
filename
<?php $hoge = 'はろー'; ?>

<script type="text/javascript">
    var hoge = <?php echo json_encode($hoge); ?>;
    console.log(hoge); // はろー
</script>

これで行けた。
XSSの可能性があるため、json形式にして渡す

50
37
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
50
37

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?