Recently used H5 for mobile phone development, because it is the window operating system, in order to facilitate development and debugging, directly in the Chrome browser test, and then on the Android handset test, when the function is basically completed, the original on the Android operation of the normal application, Running on iOS, there are a lot of strange problems, according to the troubleshooting, found that because the cookie did not get the value of the relevant information can not be obtained.
First thought is a cookie Chinese garbled problem, and later tracked found that the value of the cookie was not assigned to success, online search data, found that Safari does not allow non-ASCII encoded values, in other words: Chinese storage is not allowed.
To solve this problem, you must encode the cookie value and then decode it when the value is taken.
Back-end settings cookies with the ASP.net, the front-end to obtain the use of JavaScript, their encoding and decoding can be consistent? You can only try it now:
Several methods were tried, and the Httputility.urlencode () was found to be successful in encoding:
cookie = new HttpCookie ("Rdname");
Cookie. Value = Httputility.urlencode (user. Registerdeptname);
Cookie. Expires = System.DateTime.Now.AddDays ();
Context. Response.Cookies.Set (cookie);
Client JavaScript is decoded as:
var deptname = Cookie (' Rdname ');
Deptname= decodeuricomponent (deptname);
$ ("#pickerlb"). Val (Deptname);
That is, the decodeuricomponent () and C # Httputility.urlencode () in JavaScript are paired.
This safari cookie set Chinese failure to solve the problem is to share the whole of the content of everyone, hope to give you a reference, but also hope that we support the cloud habitat community.