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

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!