某些浏览器(Explorer / Firefox)无法识别UTF-8特殊字符

时间:2013-08-30 15:18:16

标签: internet-explorer firefox utf-8

我正在使用脚本来显示数据库中的文本,这在Chrome中运行得很好,但在Explorer和Firefox中却不行。问题可能在于特殊字符(UTF 8)。 即名字选择彼得在IE / FF中工作正常,并显示彼得信息,但Désiree没有显示任何Désiree信息(但它存在且Chromes显示它),这可能是由特殊的é-字符引起的。 因此,HTML标题和脚本代码,希望有人能为我提供正确的解决方案吗?

<head>    
<link rel='stylesheet' type='text/css' href='css/ola.css'  />
<link rel='stylesheet' type='text/css' href='css/ola_table.css' />
<meta http-equiv="content-type" content="text/html; charset=utf-8"></meta>
</head>

--+--

<script>
function showUser(str, strKlas, strPer)
{
//alert("Binnen: " + str + " - Klas: " + strKlas + " - Periode: " + strPer);
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getuser.php?klas="+strKlas+"&periode="+strPer+"&q="+str,true);
//xmlhttp.open("GET","getuser.php?klas=4B1&periode=1&q="+str,true);
xmlhttp.send();
}

</script>

1 个答案:

答案 0 :(得分:0)

在IE11之前,Internet Explorer不会自动URLEncode传递给XmlHttpRequest对象的open方法的URL参数中的字符。

您应该使用encodeURIComponent方法明确地对网址进行编码。

所以:

xmlhttp.open("GET","getuser.php?klas=" + encodeURIComponent(strKlas) + 
    "&periode="  +encodeURIComponent(strPer) + 
    "&q="+encodeURIComponent(str), true);
相关问题