Solution to the garbled code returned by php ajax: 1. Add "@header('Content-type: text/html;charset=UTF-8');" to the php ajax page; 2. Through mysql_query Set the encoding; 3. Convert the encoding through iconv.
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
How to solve the problem of php ajax returning garbled characters?
The problem of Ajax returning garbled characters in PHP
Description:
Call the PHP page through $.ajax of jquery and return after json_encode.
Error:
keeps appearing. For example: ???X3 and other errors cannot be used normally.
Solution:
1. Add: @header('Content-type: text/html;charset=UTF-8');
2. Before mysql_query, add: mysql_query(" set names utf8;");
3. Try: iconv("gb2312", "utf-8", "Chinese characters");
Recommended learning: "PHP Video Tutorial》
The above is the detailed content of How to solve the problem of php ajax returning garbled characters. For more information, please follow other related articles on the PHP Chinese website!