Home >Web Front-end >JS Tutorial >Two solutions to solve the problem of garbled characters when Jquery load() loads GB2312 pages_jquery

Two solutions to solve the problem of garbled characters when Jquery load() loads GB2312 pages_jquery

WBOY
WBOYOriginal
2016-05-16 17:22:561263browse

Problem description: The character set of jquery is utf-8. After the load method loads the GB2312 encoded static page, Chinese garbled characters appear.

a.php

Copy code The code is as follows:


Click to load page b


b.php
Copy code The code is as follows:

echo "I have Chinese here";
?>

Solution:

Method 1: Convert the encoding format of the two pages to utf8

Method 2: Add a line at the beginning of b.php: header("Content-type : text/html; charset=gb2312");

a.php is changed to (it should be fine without changing it):
Copy code The code is as follows:

$("#job").load('b.php',function(rText){
$("#job"). html(rText);
});

Problem solved.

If you are using the smarty template engine and a.php loads the template b.html, you must first make the php tag available, and then add: {php}header("Content-type : text/html; charset=gb2312");{/php}
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