如何在PHP中获取JavaScript变量值我想要使用PHP可以访问的JavaScript变量的值。我使用下面的代码,但它不返回PHP中该变量的值。// set global variable in javascript profile_viewer_uid = 1;// php code$profile_viewer_uid=$_POST['profile_viewer_uid']; 这给了我以下错误: -A PHP Error was encounteredSeverity: NoticeMessage: Undefined index: profile_viewer_uid我使用的另一个PHP代码给出空值$profile_viewer_uid = "<script language=javascript>document.write(profile_viewer_uid);</script>当我回声时它什么也没有显示。
3 回答
![?](http://img1.sycdn.imooc.com/54584f3100019e9702200220-100-100.jpg)
繁花不似锦
TA贡献1851条经验 获得超4个赞
以下是工作示例:在同一页面上获取javascript变量值。
<script>var p1 = "success";</script><?php echo "<script>document.writeln(p1);</script>";?>
![?](http://img1.sycdn.imooc.com/545868330001e54e02200220-100-100.jpg)
桃花长相依
TA贡献1860条经验 获得超8个赞
添加一个包含您要访问的javascript变量的cookie。
document.cookie="profile_viewer_uid=1";
然后通过php访问它
$profile_viewer_uid = $_COOKIE['profile_viewer_uid'];
添加回答
举报
0/150
提交
取消