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

前端 未结 7 1128
轮回少年
轮回少年 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:23

    If you want to maintain a clearer separation of PHP and JS (it makes syntax highlighting and checking in IDEs easier) then you can create jquery plugins for your code and then pass the $_SESSION['param'] as a variable.

    So in page.php:

    
    
    

    Then in my_progress_bar.js:

    (function ($) {
        $.my_progress_bar = function(percent) {
            $( "#progressbar" ).progressbar({
                value: percent
            });
        };
    })(jQuery);
    

提交回复
热议问题