" for HTML pages and "header("Content-type: text/html; for PHP files). charset=utf8");"."/> " for HTML pages and "header("Content-type: text/html; for PHP files). charset=utf8");".">

Home  >  Article  >  Web Front-end  >  How to solve Jquery load() garbled code

How to solve Jquery load() garbled code

coldplay.xixi
coldplay.xixiOriginal
2020-12-03 16:53:303493browse

Solution: Convert the encoding format of the relevant page to utf8; use "1fc2df4564f5324148703df3b6ed50c1" 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>

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");

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!

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