Home > Backend Development > PHP Tutorial > Solve the problem of garbled Chinese characters in ajax interaction on pages encoded as gb2312_PHP tutorial

Solve the problem of garbled Chinese characters in ajax interaction on pages encoded as gb2312_PHP tutorial

WBOY
Release: 2016-07-13 10:54:15
Original
977 people have browsed it

Solve the problem of garbled Chinese characters in ajax interaction on pages encoded as gb2312
Ajax only supports utf-8 format and cannot support gb2312 encoding format, so we often encounter garbled characters when using gb2312 encoding programs using ajax. I just found a solution:

The data transmitted by the server is still gb2312 encoded, and the client uses js to convert Chinese characters into utf8 encoding and display it on the page

search.php tutorial
header("content-type: text/html; charset=gb2312");
include './search.htm';
?>

search.htm




Advanced Search


Advanced Search



School type:

School name:




ajax.php

header("content-type: text/html; charset=gb2312");
$schooltype = !empty($_post['schooltype']) ? $_post['schooltype'] : 0;
switch($schooltype) {
case 0:
echo "[['40', 'Taipingxi Town Hualibao Complete Primary School'],['41', 'Taipingxi Town Changling Heilongjiang Hope Primary School'],['42', 'Letianxi Town Junior High School'], ['43', 'Letianxi Town Liantuo Junior High School']]";
         break;
Case 1:
echo "[['40', 'Taipingxi Town Hualibao Complete Primary School'],['41', 'Taipingxi Town Changling Heilongjiang Hope Primary School']]";
         break;
Case 2:
echo "[['42', 'Lotte Creek Town Junior High School'],['43', 'Lotte Creek Town Liantuo Junior High School']]";
         break;
Default:
         break;
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632334.htmlTechArticleSolve the problem of garbled Chinese characters in ajax interaction on pages encoded as gb2312. Ajax only supports utf-8 format and cannot support gb2312 encoding format. Therefore, we often encounter garbled codes when using ajax in programs encoded by gb2312...
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