两个网页都在同一文件夹下
index.html后会获取source.html代码,但是传回来的是乱码文字,两个网页都是gbk代码的,请问怎么解决这个问题?
index.html 代码如下:<html>
<head>
<title>load</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript" src="http://localhost/leb/auto/js/jquery-latest.js"></script>
<script type="text/javascript">
$(function(){
$.ajax({
url:"http://localhost/leb/jquery_ajax/source.html",
cache:false,
success:
function(html){
$(".page").append(html);
}
});
});
</script>
</head>
<body>
<div class="page">
<div class="head"></div>
<div class="body"></div>
<div class="foot"></div>
</div>
</body>
</html>source.html 代码如下:<body>
<div class="page">
<div class="head">头部</div>
<div class="body">
<p>身体</p>
</div>
<div class="foot">腿部</div>
</div>
</body>

解决方案 »

  1.   

    直接URL请求 查看返回页面是否乱码另外感觉返回页面中不应该加 <body>
      

  2.   

    $.ajax({
                url:"http://localhost/leb/jquery_ajax/source.html",
                cache:false,
                success:
                    function(html){
                        $(".page").append(html);
                    }
            });
    你是使用get方法提交还是post方法提交,如果你是get方法提交,那你得去server.xml配置文件(tomcat)中的节点:Connector 中加入:URIEncoding="GBK"
      

  3.   


      $(function(){
            $.ajax({
                url:"http://localhost/leb/jquery_ajax/source.html",
                cache:false,
                dataType:html,
                success:
                    function(html){
                        $(".page").append(html);
                    }
            });
        });加上dataType
      

  4.   

    server.xml是什么东东?在哪里?
      

  5.   


    http://localhost/leb/jquery_ajax/source.html
    你请求页面的路径直接浏览器浏览这个路径查看返回的是否是乱码(我估计就是乱码)
    所以尝试设置response的编码GBK
      

  6.   

    在javascript中,encodeURI之后的数据是utf-8的
      

  7.   

    这个我知道,听说统一外utf-8就不会有问题,但我是必须要gbk的
      

  8.   

    那你试下这样    $(function(){
            $.ajax({
                url:"http://localhost/leb/jquery_ajax/source.html",
                cache:false,
                dataType:"text", 
                success:
                    function(html){
                        $(".page").html(html)
                    }
            });
        });
    首先建议把返回的文本中<body>去掉
      

  9.   

    不行的,还是乱码。
    还有个问题,就是如何加载某个区域内容?,如我只需要source.html中的.body发送到index.html中去,怎么写?
      

  10.   

    貌似后台输出必须是UTF-8,因为jquery会把接收的东西都当成UTF-8的,所以,除非你修改jquery的代码,后台输出必须得是UTF-8
      

  11.   

    "<div class="foot">腿部</div>"  ^_^AJAX发送数据:前端编码,后端解码
    AJAX接收数据:后端编码,前端解码
      

  12.   

    晕倒 csdn 登录了还是看不了最佳答案