During WEB development, consistent data encoding is often required at the front and back ends!
On pages with non-English character sets, if Ajax is used for data interaction, you must ensure the unified encoding of the front and back ends of the data. Otherwise, garbled characters may easily occur!
When the backend is an ASP program, you can use the following functions to ensure the unified encoding of the values transmitted between the front-end Javascript and Asp:
Encoding: escape (string)
Decoding: unescape (string)
Both functions exist in JavaScript and Asp, and the functions are the same. As long as any end transmits data to the other end, escape is used for encoding, the recipient end is decoded using unescape to ensure that no garbled code occurs during Javascript and Asp data transmission!
When the backend is a PHP program, you can use the following functions to ensure the unified encoding of the values transmitted between the front-end Javascript and PHP:
WEB Front-end JavaScript
Encoding: encodeURI (string)
Decoding: decodeURI (string)
WEB backend Php
Encoding: urlencode (string)
Decoding: urldecode (string)
Similarly, when passing values, use the corresponding encoding function encodeURI or urlencode. When receiving values, use the corresponding decoding function decodeURI or urldecode to ensure that no garbled code occurs during Javascript and Php data transmission!
In the WEB Front-end Javascript decoding, when urlencode-encoded data in Php, it may need to be decoded twice, for example:
Unescape (decodeURI (string ))
Unescape is used to extract non-character texts, such as punctuation marks.