简体   繁体   English

PHP会话变量未传递给JS变量

[英]PHP Session Variable not being passed to JS variable

I'm trying to save a PHP Session variable called user_login in a JS variable called name. 我正在尝试将名为user_login的PHP会话变量保存在名为name的JS变量中。 I need to get the value from the session variable. 我需要从会话变量获取值。 Nothing worked so far and all I am getting passed to my alert is: 到目前为止,没有任何工作,并且我要传达给我的警报是:

<?php echo rawurlencode($_SESSION['user_login']); ?>

 $(document).ready(function() { var name = decodeURIComponent("<?php echo rawurlencode($_SESSION['user_login']); ?>"); alert(name); setTimeout(function() { if (name.length > 0) { $('h3.name').html(name); $('h3.name').css({ display: 'block' }); } }, 200); }); 

Seems the php code isn`t evaluated. 似乎未对php代码进行评估。

Check if the php works for this file. 检查php是否适用于该文件。

The source of the page being served by the web server should look like this: Web服务器正在提供的页面来源应如下所示:

    **decodeURIComponent("some value");**

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM