Reputation: 23
I want to change code in this. change this sessionStorage to cookie in project,
sessionStorage.setItem("modelcode", modelcode);
sessionStorage.setItem("setuptypecode", setuptypecode);
var modelcode = sessionStorage.getItem("modelcode");
var setuptypecode = sessionStorage.getItem("setuptypecode");
how can I do that?
I try to make function of setCookies and getCookies like below,
function setCookie(c_name, value, exdays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
document.cookie = c_name + "=" + c_value;
}
function getCookie(c_name) {
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++) {
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == c_name) {
return unescape(y);
}
}
}
but it didn't work.
Upvotes: 0
Views: 35
Reputation: 1001
You can manage it when ajax complete/success function get call in return after ajax call. In the ajax complete/success you can fetch the set session data and using cookie function you can set it in cookie, but you need to make everything work in ajax complete/success function.
Please let me know if you find any issues
Upvotes: 0