Home > Web Front-end > JS Tutorial > body text

How to solve Jquery load() garbled code

coldplay.xixi
Release: 2020-12-24 17:26:30
Original
3494 people have browsed it

Solution: Convert the encoding format of the relevant page to utf8; use "" for HTML pages and "header(" for PHP files. Content-type: text/html; charset=utf8");".

How to solve Jquery load() garbled code

The operating environment of this tutorial: windows7 system, jquery3.2.1 version. This method is suitable for all brands of computers.

Solution to garbled characters in Jquery load():

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

This is jQueryAJAX.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
    <title>通过jQuery AJAX改变这段文本</title>
    <script type="text/javascript" src="js/jquery-1.11.3.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $(&#39;#btn1&#39;).click(function() {
                $(&#39;#test&#39;).load(&#39;test_text.txt&#39;);
            });
        });
    </script>
</head>
<body>
    <h3 id="test">请点击下面的按钮,通过 jQuery AJAX 改变这段文本.</h3>
    <button id="btn1" type="button">获得外部的内容</button>
</body>
</html>
Copy after login

This is the content of the test_text.txt file:

Hello, this is the newly loaded text!

Solution :

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

Note: If the file is a php file: add a line at the beginning of test_text.php:

header("Content-type: text/html; charset=utf8");
Copy after login

Related free learning recommendations: javascript(Video)

The above is the detailed content of How to solve Jquery load() garbled code. 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