How to solve the problem of php ajax returning garbled characters

藏色散人
Release: 2023-03-13 15:54:01
Original
1533 people have browsed it

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!

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