Ensure unified Value Transfer Encoding between JavaScript, ASP, PHP, and other backend programs
Source: Internet
Author: User
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!
ASP ProgramIn this case, you can use the following functions to ensure the unified encoding of 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.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.