2013-06-13 19 views
1

我的網站:www.egemen.dkInternet Explorer將不會發送特殊字符

我正在開發一個網站,並在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作爲元的字符集。

+0

您正在測試什麼版本的IE? – Spudley

+0

「不正確」是什麼樣子?你得到了什麼? – deceze

回答

0

的值需要URL編碼的encodeURIComponent()

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); 
} 
+0

謝謝。當試圖這個代碼不會編譯。它給出了一個錯誤。 – user2373787

+0

@ user2373787仔細檢查你的其他代碼。答案中沒有語法錯誤。什麼是錯誤信息? – MrCode

0

一些奇怪的事情,因爲瀏覽器顯示使用Windows-1252編碼的頁面,即使頁面似乎有meta標籤,聲明UTF -8(並且HTTP標頭不指定編碼)。的解釋是,如果你有一個validator檢查代碼,你會發現有錯字的標籤:

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

utf-8前引號應該被刪除。

這會影響提交時表單數據的編碼。它在默認情況下與頁面的編碼相同。應該使用UTF-8來確保所有字符都能正確發送。