Home  >  Article  >  Web Front-end  >  How to solve jquery ajax Chinese garbled problem

How to solve jquery ajax Chinese garbled problem

藏色散人
藏色散人Original
2020-12-30 10:19:453337browse

Jquery Ajax Chinese garbled solution: 1. If the client is gb2312 encoding, specify the output stream encoding on the server; 2. Both the server and the client use utf-8 encoding.

How to solve jquery ajax Chinese garbled problem

The operating environment of this tutorial: Dell G3 computer, Windows 7 system, jquery1.10.0 version.

Recommended: "javascript basic tutorial"

jquery ajax garbled code problem

Cause of garbled code:

1. The default character encoding of data returned by xtmlhttp is utf-8. If the client page is gb2312 or other encoded data, garbled characters will be generated

2. The default character encoding of data submitted by the post method is utf- 8. If the server is gb2312 or other encoded data, garbled characters will be generated.

The solutions are:

1. If the client is gb2312 encoded, specify the output stream encoding on the server.

2. Both the server and the client use utf-8 encoding

gb2312:header('Content-Type:text/html;charset=GB2312');
utf8:header('Content-Type:text/html;charset=utf-8');

Note:

If you have followed the above method and still return garbled characters, check your method Whether it is get, for get requests (or any involving url passed parameters), the passed parameters must first be processed by the encodeURIComponent method.

If encodeURIComponent is not used, garbled characters will also be generated.

For more programming-related knowledge, please visit: Programming Teaching! !

The above is the detailed content of How to solve jquery ajax Chinese garbled problem. For more information, please follow other related articles on the PHP Chinese website!

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