javascript - Alternative to session variable in my scenario -
i have miniview pops out , popsin on user click. has retain state between pages. if user opens miniview , goto page , comeback, should open.i have done using session variable.. code is:
html:
<input type="hidden" value="@session["miniviewstatus"]" id="miniviewstatus" />
javascript:
$(".pullout_ico").click(function() { var url = "/studentinformation/getminiviewstatus"; $.post(url, { status: "true" }, function (data) { openminiview(); }); }); $(".pullout_button").click(function() { var url = "/studentinformation/getminiviewstatus"; $.post(url, { status: "false" }, function (data) { closeminiview(); }); }); var status = $("#miniviewstatus").val(); if (status == "true") { openminiview(); } if (status == "false") { closeminiview(); } function openminiview() { $(".pullout_block").show(250); $(".pullout_ico").hide(100); $(".left_content").removeclass("bigger_left_content"); } function closeminiview() { $(".pullout_ico").show(100); $(".pullout_block").hide(250); $(".left_content").addclass("bigger_left_content"); } };
studentinformation controller has getminiviewstatus sets string value. now,it works fine, dont way. there anyway, can store status between dom loads??
as ravi answers in comment, cookies solution when using js , doing things on client side. give little more detail, use jquery-cookie plugin , set cookie. change code following, , eliminate server side support ajax actions.
$(".pullout_ico").click(function() { $.cookie("miniviewstatus", true); }); $(".pullout_button").click(function() { $.cookie("miniviewstatus", false); }); var status = $.cookie("miniviewstatus"); if (status) { openminiview(); } else { closeminiview(); } function openminiview() { $(".pullout_block").show(250); $(".pullout_ico").hide(100); $(".left_content").removeclass("bigger_left_content"); } function closeminiview() { $(".pullout_ico").show(100); $(".pullout_block").hide(250); $(".left_content").addclass("bigger_left_content"); }
Comments
Post a Comment