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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742411151a4438838.html
评论列表(0条)