How to access PHP session variables from jQuery function in a .js file?

前端 未结 7 1162
轮回少年
轮回少年 2020-11-28 10:50

How to access PHP session variables from jQuery function in a .js file? In this code, I want to get \"value\" from a session variable

$(function() {
   $(\"#         


        
7条回答
  •  伪装坚强ぢ
    2020-11-28 11:25

    I was struggling with the same problem and stumbled upon this page. Another solution I came up with would be this :

    In your html, echo the session variable (mine here is $_SESSION['origin']) to any element of your choosing :

    In your js, using jQuery you can access it like so : $("#sessionOrigin").text();

    EDIT: or even better, put it in a hidden input

提交回复
热议问题