javascript - How to use "Session" in jQuery? - Stack Overflow

Is there a similar functionality in jQuery as Session["Param"] in C#? How can I use it? I

Is there a similar functionality in jQuery as Session["Param"] in C#? How can I use it?

I've searched "sessionStorage" in jQuery, but I can't understand.

Is there a similar functionality in jQuery as Session["Param"] in C#? How can I use it?

I've searched "sessionStorage" in jQuery, but I can't understand.

Share Improve this question edited Jul 27, 2016 at 17:56 TankorSmash 12.8k6 gold badges70 silver badges108 bronze badges asked Jul 27, 2016 at 17:47 Eric SaboiaEric Saboia 3212 gold badges10 silver badges22 bronze badges 1
  • No need for jQuery, developer.mozilla/en-US/docs/Web/API/Window/sessionStorage – Alexander O'Mara Commented Jul 27, 2016 at 17:49
Add a ment  | 

4 Answers 4

Reset to default 6

As you said, you can use sessionStorage in JavaScript.

▶ You can set a new parameter like so:

sessionStorage.param1 = "Hello";
/* Or */
sessionStorage.setItem("param1", "Hello");

▶ Then, you can get it as follows:

var param = sessionStorage.param1;
/* Or */
var param = sessionStorage.getItem("param1");

console.log(param); /* It'll output `Hello`. */

Notes:

▶ Using sessionStorage, you can only store data for one session, which means everything will be deleted if you close the specific browser tab. If you want to permanently store data use localStorage instead.

▶ As you are apparently very new to JavaScript, I suggest you take a look at the following documentation about Web Storage in JavaScript:

  • Mozilla Development Network (sessionStorage, localStorage)
  • W3 Schools (both)
// ${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

The following can be used to store and retrieve data in the following ways:

To store:

sessionStorage.setItem("error", 'some value');

To retrieve:

sessionStorage.getItem("error");

To use session data ,you don't need jquery you can use setItem ,getItem and removeItem to deal with the session data which is stored as a json object and accessible via key.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742411151a4438838.html

相关推荐

  • javascript - How to use &quot;Session&quot; in jQuery? - Stack Overflow

    Is there a similar functionality in jQuery as Session["Param"] in C#? How can I use it? I

    14小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信