admin管理员组文章数量:1336576
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.
- No need for jQuery, developer.mozilla/en-US/docs/Web/API/Window/sessionStorage – Alexander O'Mara Commented Jul 27, 2016 at 17:49
4 Answers
Reset to default 6As 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.
本文标签: javascriptHow to use quotSessionquot in jQueryStack Overflow
版权声明:本文标题:javascript - How to use "Session" in jQuery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742411150a2469812.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论