繁体   English   中英

Internet Explorer不会发送特殊字符

[英]Internet explorer won't sent special characters

我的网站:www.egemen.dk

我正在开发一个网站,并在IE上遇到特殊字符问题。 我的网站上有一个带有多个姓氏的下拉框。 这些姓氏可以包含特殊字符,例如ô,î,ö等。从数据库获取这些姓氏以构建下拉列表时,一切工作正常,并且可以正确显示特殊字符,但是,用户应该能够选择姓氏并执行搜索。 选择带有特殊字符的姓氏时,代码将调用javascript方法以连接到数据库。 在FF和safari中可以使用,但在IE中无法将这些特殊字符正确发送到javascript。 任何想法?

Javascript:

<script>
function searchUser(str)
{
    var call ="/Data/controller.php?cmd="+str;
    if(str == "searchByName"){
        call += "&name=" + document.getElementById("s_name").value;
        call += "&lname=" + document.getElementById("s_lname").value;
    }
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", call ,true);
    xmlhttp.send();
    }
    </script>

Index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1  /DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />

我也尝试过使用utf-8作为meta中的字符集。

值需要使用encodeURIComponent()进行URL编码

var call ="/Data/controller.php?cmd="+encodeURIComponent(str);
if(str == "searchByName"){
    call += "&name=" + encodeURIComponent(document.getElementById("s_name").value);
    call += "&lname=" + encodeURIComponent(document.getElementById("s_lname").value);
}

发生了一些奇怪的事情,因为浏览器使用Windows-1252编码显示该页面,即使该页面似乎具有声明UTF-8的meta标签(并且HTTP标头未指定编码)。 解释是,如果您使用验证器检查代码,则会看到标记中有错字:

<meta http-equiv="content-type" content="text/html; charset="utf-8" />

utf-8之前的引号应删除。

提交时,这会影响表单数据的编码。 默认情况下,它与页面的编码相同。 它应该是UTF-8,以确保所有字符都可以正确发送。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM