将变量从php传递给javascript

编程入门 行业动态 更新时间:2024-10-09 23:14:24
本文介绍了将变量从php传递给javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试创建一个网站,有人可以创建一个项目,数据库将存储一个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

本文发布于:2023-11-24 22:04:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627034.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   php   javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!