Home > Web Front-end > JS Tutorial > body text

Ensure uniform encoding of value transfers between JavaScript and back-end programs such as Asp and Php_javascript skills

WBOY
Release: 2016-05-16 18:53:58
Original
972 people have browsed it

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!