Home > Article > Backend Development > How to solve the Chinese garbled problem of php xmlhttprequest
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.
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");
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!