Chinese cannot be directly stored in the cookie, cookie transcoding and decoding

If Chinese is stored in the cookie, problems will easily occur. 
When js is stored in a cookie, the escape () function can be used to encode the string. The decoding
order with unescape () is to encode the  cookie with the escape () function and then save it, and then take it and then use unescape () to transfer Code, so that's no problem

1 setCookie ("username", escape (username), 3) // code the cookie value in advance, and then call the setCookie function to store it in the browser cookie 
2 
3 unescape (getCookie ("username")); // in Where you need cookies, use the custom function getCookie to take it out and transcode
Published 51 original articles · 19 praises · 60,000+ views

Guess you like

Origin blog.csdn.net/qq_40999917/article/details/104939160