Ajax中文乱码解决方案

  

方案一:web端和服务器端处理

 

web端:

if(trim(cellphone).length>0 && trim(expert_name).length>0 ){
      var url = "ebsservlet?reqCode=<%=OperCode.EXPERTINFO_CHECKNAMEAJAX%>";
      url += "&expert_name="+trim(expert_name);
      url += "&cellphone="+trim(cellphone);
      req.open("GET",encodeURI(encodeURI(url)),true);
      req.onreadystatechange = callback3;
      req.send(null);
  }

 

服务器端转换:expert_name=java.net.URLDecoder.decode(expert_name,"UTF-8");

 

方案二:服务器端直接转换

req.setCharacterEncoding("utf-8");
expert_name = new String(expert_name.getBytes("ISO-8859-1"),"GBK");

你可能感兴趣的:(Ajax,Web,.net)