On pages with non-English character sets, if you use Ajax for data interaction, you must pay attention to ensuring that the front-end and back-end data are uniformly encoded, otherwise, garbled characters will easily appear!
When the backend is an ASP program, maintaining the unified encoding of values transferred between the front-end Javascript and Asp can be processed using the following functions:
Encoding: escape(string)
Decoding: unescape(string)
These two functions exist in both JavaScript and Asp, and their functions are exactly the same. As long as any end transmits data to the other end, it is encoded with escape first, and the receiving end is decoded with unescape to ensure that the Javascript and Asp data are There will be no garbled characters during transmission!
When the backend is a PHP program, maintaining the unified encoding of values transferred between front-end Javascript and PHP can be processed using the following function:
WEB front-end JavaScript
Encoding: encodeURI(string)
Decoding: decodeURI(string)
WEB backend Php
Encoding: urlencode(string)
Decoding: urldecode(string)
Similarly, when passing a value, use the corresponding encoding function encodeURI or urlencode to receive When using the corresponding decode function decodeURI or urldecode, you can ensure that no garbled characters will appear during the data transfer process of Javascript and Php!
When decoding the WEB front-end Javascript and urlencode-encoded data in Php, you may need to use two decodes, such as:
unescape(decodeURI(string))
unescape is used to decode some non-character text. Such as punctuation marks, etc.