" 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 >Web Front-end >JS Tutorial >How to solve Jquery load() garbled code
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");".
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() { $('#btn1').click(function() { $('#test').load('test_text.txt'); }); }); </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!