doudu22272099831 2016-03-13 20:18
浏览 64
已采纳

在jquery mobile中获取php会话值

Am creating a page in jquery mobile whereby a jquery function is supposed to check for the set php session variable but i get an error of syntax error in the console.

The code:

$(document).on("pageshow","#schoolperformance", function(){ 

var sessName = '<?php echo json_encode($_SESSION['schoolname']); ?>';

 alert(sessName);

});

When i check the value of $_SESSION['schoolname'] in a normal way via a raw php script it returns a value of the session.

THE FILE IS A JAVASCRIPT FILE that is saved as a .js file

  • 写回答

1条回答 默认 最新

  • douqianzha6213 2016-03-13 20:22
    关注

    Change the single quote at this line

    var sessName = '<?php echo json_encode($_SESSION['schoolname']); ?>';
    

    To double quotes

    var sessName = "<?php echo json_encode($_SESSION['schoolname']); ?>";
    

    The sessName variable string is breaking up by using single quotes surrounding the string and php variable. because its stops right at ['

    UPDATE:

    As you say in your comments that you trying to perform PHP in .JS files that is totally wrong, because for PHP to work you need to use .PHP file extensions not .JS extensions

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决