Reputation: 467
I have a form with several entries that I am serializing with jQuery into a string. I am then simply using:
document.cookie = string + "expires=" + expires;
This way all of the form fields are in this one cookie, ampersand delimited, and all share the same expiration date. My question as a novice programmer, is this very bad practice to do?
Upvotes: 1
Views: 813
Reputation: 2972
It's absolutely normal to have multiple key/value pairs in a cookie. Just watch out because older browsers cap string length. If that's not a problem for you since you aren't using older browsers, I'd just use local storage instead and send an object to local storage.
Just look at the cookies that Stack Overflow sets.... specifically the _utmz It looks like they set the delimiter to |
Upvotes: 1
Reputation: 1027
should be Ok if you are careful not to exceed the cookie size limits. AFAIK 4K. you can check this answer as well What is the maximum size of a web browser's cookie's key?
Upvotes: 0