我正在尝试创建一个网站,有人可以创建一个项目,数据库将存储一个id,php会为该id生成一个url。因此,下次当该人返回该网址时,它将记住该人的设置(变量)。现在的问题是,在我的网站中,javascript需要知道这些变量。
I am trying to create a site where someone can create an "item" and the database will store an id and php generates a url for that id. So next time when the person comes back with that url it will remember the person's settings (variables). Now the problem is that in my site javascript need to know these variables.
那么最佳解决方案是什么?传递超全球GET中的变量或者cookie?或者有更好的方法将这些变量传递给javascript吗?
So what is the best solution for this? passing the variables in the superglobal "GET" or maybe cookies? Or is there a better way to pass these variables to javascript?
推荐答案只需使用php打印一些动态javascript
just use php to print some dynamic javascript
<script> var myVar = "<?php echo json_encode($_COOKIE['somevalue']);?>"; </script>更多推荐
将变量从php传递给javascript
发布评论