How to solve the Chinese garbled problem of php xmlhttprequest

藏色散人
Release: 2023-03-14 19:40:01
Original
2662 people have browsed it

php Solution to Chinese garbled characters in xmlhttprequest: 1. Unify to UTF-8; 2. When outputting text obtained through XMLHttpRequest, just add text declarations in headers.

How to solve the Chinese garbled problem of php xmlhttprequest

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How to solve the Chinese garbled problem of php xmlhttprequest?

Solving the problem of Chinese garbled characters in XMLHttpRequest

The default character encoding for data obtained through XMLHttpRequest is UTF-8. If the front-end page is GB2312 or other encoding, the data obtained is displayed as garbled characters. . Through XMLHTTPRequest, the POST data is also UTF-8 encoded. If the background is GB2312 or other encoding, garbled characters will appear.

Solution:

  • Unify to UTF-8. This is also an inevitable trend of internationalization.

  • When outputting text obtained through XMLHttpRequest, add text declarations in headers (direct HTML declarations have no effect).

For example:

PHP:header('Content-Type:text/html;charset=GB2312');
ASP:Response.Charset = "GB2312"
JSP:response.setHeader("Charset","GB2312");
Copy after login

Recommended learning: "PHP Video Tutorial"

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

Related labels:
php
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