Tom Gullen
Tom Gullen

Reputation: 61725

Jquery stop HTML encoding cookie

I'm using this short snippet of code:

var d = itemID + "," + quantity;
var CookieData = $.cookie("storebasket");

if(CookieData == null || CookieData == "") {
    $.cookie("storebasket", d, { path: '/', expires: 60 });
} else {
    $.cookie("storebasket", CookieData + "|" + d, { path: '/', expires: 60 });
}

However the value ALWAYS becomes HTML encoded. For example:

5%2C1

Which when decoded with this tool is:

5,1

I've tried using unescape but no luck:

$.cookie("storebasket", unescape(d), { path: '/', expires: 60 });

Any more ideas?

Upvotes: 7

Views: 5358

Answers (2)

brad oyler
brad oyler

Reputation: 3780

jquery.cookie is encoding the comma by default. To override this just do:

$.cookie.raw = true;

Upvotes: 13

Jonny Burger
Jonny Burger

Reputation: 921

This answer is really useful:

Allowed characters in cookies

But I really don't see the problem. When you want to use them in your document, you can unescape them. If you want to store them in the cookies, they are being escaped.

Upvotes: 0

Related Questions