解决ajax乱码方案 持续更新中....

本文介绍了一种解决通过GET方法加载HTML静态页面时出现乱码的问题。具体解决方案是使用Notepad等文本编辑器将文件另存为UTF-8格式。此外,还提供了JavaScript实现的AJAX请求示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 网上太多方法了,有的能用有的不能用,自己碰到的写下吧

1:下面这个是Get 方法  xmlHttp.open("GET", webFileUrl);一个html表态页,发现返回是乱码, 

解决办法,将这个静态页面用notepad打开,另存为UTF-8格式 即可

 

var xmlHttp ;
  function GetDetails()
  {
    var webFileUrl = "";
     //正常后台生成 webFileUrl = window.frames["ifr2"].location.href="getExList.aspx";
     
     webFileUrl="js/ExPreView.html"
      
     //开始取值过程
     xmlHttp = CreateHTTPObject();
     //正常后台生成 xmlHttp.open("POST", webFileUrl, false);
     xmlHttp.onreadystatechange = handleStateChange;
     xmlHttp.open("GET", webFileUrl);
     
     xmlHttp.send("");
    
  }
  

function handleStateChange(){           
 if(xmlHttp.readystate == 4){   
  if(xmlHttp.status == 200){
   document.getElementById("exlist").innerHTML  = xmlHttp.responseText;
                       }
                    }
}
 
function CreateHTTPObject()
{
  var xmlhttptemp;
 
  try
   {
    xmlhttptemp = new ActiveXObject("Msxml2.XMLHTTP");
   }
    catch (e)
    {
     try
        {
           xmlhttptemp = new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
     {
           xmlhttptemp = false;
        }
   }
  
   if (!xmlhttptemp && typeof XMLHttpRequest!='undefined')
   {
      try
    {
       xmlhttptemp = new XMLHttpRequest();
   }
      catch (e)
      {
        xmlhttptemp=false;
     }
   }
 
 if (!xmlhttptemp && window.createRequest)
   {
   try
     {
        xmlhttptemp = window.createRequest();
     }
  catch (e)
    {
       xmlhttptemp=false;
    }
 }
 return xmlhttptemp;
}    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值