Home >Web Front-end >JS Tutorial >Experience in dealing with garbled characters in JavaScript_javascript skills

Experience in dealing with garbled characters in JavaScript_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:38:211263browse
Common garbled characters:
1. The client submits data to the background, and the parameter values ​​are garbled, such as: a.aspx?value="Chinese value"&type="%$#((&_ Special symbols";
2. Garbled characters appear after reading data in the background to the client;
3. The js references or css styles between some files are invalid.

Summary of solutions:
1: First, ensure that the file format encoding (i.e. save as format) related to the project is unified to utf-8, especially the format of related CSS and JS files is strongly recommended to be unified to utf-8;

2 : JS involves parameter submission and transmission. Where Chinese, '_' underline, and special symbols may appear, use escape() to encode them before passing them;

Three: If different values ​​have been stored in the database before For the encoded data, set the ContentEncoding attribute encoding of Request and Response to "utf-8" in the background of the relevant display data page

In this way, garbled characters will not reappear

Other netizens responded:
Compile it with Google Clsure Compiler and you can convert Chinese into unicode expression. It doesn’t matter what encoding you use.
Statement:
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