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条回答 默认 最新

    报告相同问题?