简体   繁体   English

Internet Explorer不会发送特殊字符

[英]Internet explorer won't sent special characters

My website: www.egemen.dk 我的网站:www.egemen.dk

I'm developing a website and have problems with special characters on IE. 我正在开发一个网站,并在IE上遇到特殊字符问题。 On my website there is a dropdown box with a number of lastnames. 我的网站上有一个带有多个姓氏的下拉框。 These lastnames can contain special characters like ô, î,ö, etc. Everything works fine when getting these lastnames from database to build the dropdown and special characters are displayed correctly, however, the user should be able to select a lastname and perform a search. 这些姓氏可以包含特殊字符,例如ô,î,ö等。从数据库获取这些姓氏以构建下拉列表时,一切工作正常,并且可以正确显示特殊字符,但是,用户应该能够选择姓氏并执行搜索。 When selecting a lastname with special character, the code calls javascript method to connect to database. 选择带有特殊字符的姓氏时,代码将调用javascript方法以连接到数据库。 In FF and safari it works, but with IE it can't send these special characters correctly to the javascript. 在FF和safari中可以使用,但在IE中无法将这些特殊字符正确发送到javascript。 Any idea? 任何想法?

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 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" />

I have also tried with utf-8 as the charset in meta. 我也尝试过使用utf-8作为meta中的字符集。

The values need to be URL encoded with encodeURIComponent() 值需要使用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);
}

Something odd is going on, because browsers display the page using windows-1252 encoding, even though the page seems to have a meta tag that declares UTF-8 (and the HTTP headers do not specify encoding). 发生了一些奇怪的事情,因为浏览器使用Windows-1252编码显示该页面,即使该页面似乎具有声明UTF-8的meta标签(并且HTTP标头未指定编码)。 The explanation is that if you check the code with a validator , you'll see that there is typo in the tag: 解释是,如果您使用验证器检查代码,则会看到标记中有错字:

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

The quotation mark before utf-8 should be removed. utf-8之前的引号应删除。

This affects the encoding of the form data when submitted. 提交时,这会影响表单数据的编码。 It is by default the same as the encoding of the page. 默认情况下,它与页面的编码相同。 It should be UTF-8 to ensure that all characters will be sent correctly. 它应该是UTF-8,以确保所有字符都可以正确发送。

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

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