Home>Article>Backend Development> How to solve the problem of php ajax returning garbled characters

How to solve the problem of php ajax returning garbled characters

藏色散人
藏色散人 Original
2021-11-01 10:10:01 1459browse

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.

How to solve the problem of php ajax returning garbled characters

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!

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