I am attempting to create a cookie. I suspect that my cookie isnt saving or being retrieved properly. What am I doing wrong?
I tried 2 methods to save this cookie:
Cookie gets saved in this function:
function(config) { var config_copy = JSON.parse(JSON.stringify(config)); setCookie('key',config_copy); }Use setCookie();
function(config) { var config_copy = JSON.parse(JSON.stringify(config)); setCookie(); }
Then trigger this function:
function setCookie(key,config_copy){
document.cookie = key + "=" + config_copy;
console.log("cookie saved");
console.log(config_copy);
}
console.log(config_copy); returns undefined in the console.
How would I correctly save the value of config_copy into a JavaScript cookie?
document.cookieby typing that in console. A question, in method 2 how would you expect the arg'skey, config_copyto be defined in yoursetCookiefunction if you don't pass them?setCookie("config", config_copy)