zoukankan      html  css  js  c++  java
  • 解决jQuery load()加载GB2312页面时出现乱码

    jquery的字符集是utf-8,load方法加载完GB2312编码静态页面后,出现中文乱码.

    这是jQueryAJAX.html

     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
     3 <head>
     4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
     5     <title>通过jQuery AJAX改变这段文本</title>
     6     <script type="text/javascript" src="js/jquery-1.11.3.js"></script>
     7     <script type="text/javascript">
     8         $(document).ready(function() {
     9             $('#btn1').click(function() {
    10                 $('#test').load('test_text.txt');
    11             });
    12         });
    13     </script>
    14 </head>
    15 <body>
    16     <h3 id="test">请点击下面的按钮,通过 jQuery AJAX 改变这段文本.</h3>
    17     <button id="btn1" type="button">获得外部的内容</button>
    18 </body>
    19 </html>

    这是test_text.txt文件内容:

    你好,这是新加载的文字!

    解决办法:

    方法:将两个页面的编码格式转换成utf8.

    注明:如果要价在的文件是php文件:在test_text.php开头加入一行:header("Content-type: text/html; charset=utf8");

  • 相关阅读:
    getRandomInt getRandomString
    git 换行符替换
    Versions maven plugin 修改版本
    spotless-maven-plugin java代码自动格式化mvn spotless:apply -fn
    eclipse.ini
    JVM架构和GC垃圾回收机制
    查看搜狗浏览器记住的密码
    TestGc finalize()
    Storm个人学习总结
    mongo嵌套查询
  • 原文地址:https://www.cnblogs.com/liubeimeng/p/4980829.html
Copyright © 2011-2022 走看看