king1988
king1988

Reputation: 23

how to get custom type value from session variable in jquery?

i'm just want to know is there any way to get the custom type value from session variable in jquery?

for example. i have a class named user.

public class user{
    public string userid;
    public string username;
}

public static class Abc
{
    public static List <user> user; //user type list
}

and in session variable i have session["userclass"] = Abc.user;

now the question is how to get value from this session variable using jquery.

i know about var abc = <%=session["variablename"]%>

but how to get value of the user class variables using above session variable in jquery?

Upvotes: 0

Views: 345

Answers (2)

Pradip Wawge
Pradip Wawge

Reputation: 131

// ${FEEDBACK_QUESTION_IDS} this is session attribute name in controller

<script type="text/javascript">
    $(document).ready(function() {  
        window.questionIdsList = [];
        var i = 0;
        <c:forEach items="${FEEDBACK_QUESTION_IDS}" var="queId">
        questionIdsList[i] = parseInt(${queId});
        i++;
        </c:forEach>

    });
</script>
finally we can use  "window.questionIdsList" as same as array

Upvotes: 1

flyfrog
flyfrog

Reputation: 762

Because you put: "session["userclass"] = Abc.user;",

session["userclass"] is a list, not a user object.

You can code as followings:

List u = session["userclass"] as List;

User firstone = u[0] as user;

string id = firstone.userid;

Upvotes: 0

Related Questions