dongxian6285 2016-10-09 22:05
浏览 27
已采纳

使用Angular Routing时访问php会​​话

I am using Angular routing and want to access a php session variable in the view.

<?php
session_start();
//print_r($_SESSION['query']); the variable is available and will print here
?>

<script>
    var x = <?$_SESSION['query']?>
    console.log("x: " , x) //this returns undefined
</script>

I'm trying to pass the session variable as a parameter in function, but it is not available here either.

ng-init="mc.makeQuery(<?($_SESSION['query'])?>)"
  • 写回答

1条回答 默认 最新

  • douxing7101 2016-10-09 22:22
    关注

    You can start session on your page like and create hidden field for session like this

    <input type="hidden" name="mysession" id="mysession">
    

    and write javascript function some thing like this

    function Result(){
      var marks = 55;
      document.getElementById("mysession").innerHTML= <?php echo session_id();?>; 
      document.getElementById("hdnmarks").innerHTML= marks; 
      document.getElementById('Form').submit();
    }
    

    change the Form name with your form name.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部