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

How to solve jquery ajax Chinese garbled problem

藏色散人
Release: 2023-01-04 09:38:20
Original
3469 people have browsed it

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');
Copy after login

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!

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