I store Chinese characters in cookie but the cookie value changes to garbled characters. What should I do?
function createCookie(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 1000 * 60 * 60 * 24));
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
}
createCookie("city", decodeURI('%e6%b8%a9%e5%b7%9e%e5%b8%82'));
alert(decodeURI('%e6%b8%a9%e5%b7%9e%e5%b8%82')); // The Chinese characters are correct
alert(document.cookie); //The Chinese characters are corrupted