3

This is the code that I've got:

var tmp_kana_type = "hiragana";
var tmp_kana_set = "monographs";

cookie_symbols = {"symbols": []};

for (kana_row=0; kana_row<10; kana_row++) {
    for (kana_column=0; kana_column<5; kana_column++) {

        var tmp_JSON  = {
                "kana_type": tmp_kana_type,
                "kana_set": tmp_kana_set,
                "kana_row": kana_row,
                "kana_column": kana_column,
                "selected": 0,
                "correct": 0,
                "total": 0
        };

        cookie_symbols.symbols.push(tmp_JSON);
    }
}

console.log(cookie_symbols); // works

var to_string = JSON.stringify(cookie_symbols);
console.log(to_string); // works

var to_json = JSON.parse(to_string);
console.log(to_json); // works



$.cookie("test_cookie1", "test string"); 
console.log($.cookie("test_cookie1")); // works

$.cookie("test_cookie2", JSON.stringify(cookie_symbols)); // does not work (why?)
console.log($.cookie("test_cookie2")); // does not work (null)
console.log(JSON.parse($.cookie("test_cookie2"))); // does not work (null)

JSON.stringfy() is not working with $.cookie() while I believed it should. Did I do something wrong, and how do I fix or make this work? I found this answer, and it's pretty much what I did too, but in my case it doesn't work for some reason. I am using this jQuery cookie plugin.

Community
  • 1
  • 1
tkit
  • 8,082
  • 6
  • 40
  • 71
  • Why not? `to_string` != `to_sting`. – Kiruse Aug 12 '12 at 00:01
  • 1
    @Derija93 - I wrote that as an example of what I tried and what worked when I checked it in firebug console. I made a typo here and fixed it now. – tkit Aug 12 '12 at 00:03

1 Answers1

4

I believe is your main issue is that you've exceed the maximum cookie file size.

Community
  • 1
  • 1
Kiruse
  • 1,703
  • 1
  • 12
  • 23
  • I didn't even think about that... I guess I'll have to think of a different approach. Thank you. – tkit Aug 12 '12 at 00:20
  • I was just running some tests to verify that this was the correct answer but you beat me to it. – ChaosPandion Aug 12 '12 at 00:21
  • 1
    @pootzko I recommend looking into the `localStorage`. It basically works the same way, except that the storage isn't sent to the server. Thus you are likely not to have to worry about size restrictions. – Kiruse Aug 12 '12 at 00:24