weixin_33691817 2015-08-15 15:47 采纳率: 0%
浏览 5

检查会话值(ajax)

Im making a site but i want to check the value of a session so i can show a button depending on what the users role is.

the problem im having is that i cant get the value of the session into SessionValue

i will also add that the file is a .js

what i have so far:

function getGroups() {
var SessionValue = <?php print($_SESSION['user_role']); ?>;

$.ajax({
    url: 'services/functions.php',
    data: {
        action: 'getGroups'
    },
    type: 'post',
    success: function (output) {
        var result = JSON.parse(output);
        result = result.results;
        $(result).each(function (index, element) {

            var out = "<div class='row'>";
            out += "<div class='col-md-3'>";
            out += "<img class='img-responsive image_" + index + "' src=" + element.group_image + ">";
            out += "</div>";
            out += "<div class='col-md-9'>";
            out += "<h3>" + element.group_title + "</h3>";
            if(SessionValue == "admin"){
            out +=  "<button class='btn btn-primary pull-right' type='button' id='submitPost'>Delete</button>";
            }

            out += "<h4 class='hidden_" + index + "'>" + moment(element.group_playdate, 'HH:mm:ss').format('HH:mm') + "</h4>";
            out += "<p class='hidden_" + index + "'>" + element.group_description + "</p>";
            out += "</div>";
            out += "</div>";
            out += "<hr/>";

            $(".groupContainer").append(out);
            $(".hidden_" + index).hide();

            $(".image_" + index).hover(
                function () {
                    $('.hidden_' + index).fadeIn(200);
                },
                function () {
                    $('.hidden_' + index).fadeOut(100);
                }
            );
        });
    },
    error: function (output) {
        console.error("Something went wrong while loading the groups from the database.");
    }
});
}

the session is started and the user_role is also defined @login.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改
    • ¥20 wireshark抓不到vlan
    • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
    • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持