Home > Backend Development > PHP Tutorial > Ajax+php Chinese garbled solution_PHP tutorial

Ajax+php Chinese garbled solution_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-20 11:17:53
Original
988 people have browsed it

Since XMLHTTP uses Unicode encoding to upload data, and general pages use gb2312, this causes garbled characters when displaying the page. When getting the page, XMLHttp returns UTF-8 encoding, which causes garbled display.
One of the solutions is to display the declaration as GB2312

in the PHP file

header("Content-Type:text/html;charset=GB2312");

And transcode the Chinese sent to the server.
As follows
$_POST["content"]=iconv("UTF-8","gb2312",$_POST["content"]);
Therefore, this can solve the problem of garbled characters

Method 2 uses UTF-8 encoding. Not much to say here

Attached test routine
Client





ajax post test








Server side
header("Content-Type:text/html;charset=GB2312");
if($_POST['content'])
{
$_POST["content"]=iconv("UTF-8","gb2312",$_POST["content"]);
print("The content is".$_POST['content']);
}
else
{
print("No content sent");
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371911.htmlTechArticleSince XMLHTTP uses Unicode encoding to upload data, and general pages use gb2312, this causes the problem when displaying the page. Generate gibberish. When getting the page, XMLHttp returns utf-8...
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
Latest Issues
angular.js - Angularjs $http ajax issue?
From 1970-01-01 08:00:00
0
0
0
PHP does not recognize content sent by Ajax
From 1970-01-01 08:00:00
0
0
0
Opencart 2: Call php files using Ajax
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template