I have a problem with the encoding in my AJAX.
I have a website with Danish foundations - the names of these include the special characters of 'Æ', 'Ø' and 'Å'. When I filter in my dropdown menus, the special characters are displayed with a '?'.
JavaScript:
function findLegater(val1, val2, val3) {
var stu = document.getElementById(val1).value
var ud = document.getElementById(val2).value
var kva = document.getElementById(val3).value
if (stu=="N" && ud =="0" && kva =="0") {
document.getElementById("txtHint").innerHTML="";
}
else {
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","getlegat.php?s="+stu+"&u="+ud+"&k="+kva,true);
xmlhttp.send();
}
}
PHP to receive the data:
$s=$_GET["s"];
$u=$_GET["u"];
$k=$_GET["k"];
include 'msql/msql-connect.php';
if ($s!= "N" && $u != "0" && $k!="0") {
$query = "SELECT * FROM legater WHERE studiegrad LIKE '%$s%' and studie LIKE '%$u%' and kvartal LIKE '%$k%'";
}
else if ($s!= "N" && $u == "0" && $k=="0") {
$query = "SELECT * FROM legater WHERE studiegrad LIKE '%$s%'";
}
else if ($s!= "N" && $u != "0" && $k=="0") {
$query = "SELECT * FROM legater WHERE studiegrad LIKE '%$s%' and studie LIKE '%$u%'";
}
else if($s== "N" && $u != "0" && $k=="0") {
$query = "SELECT * FROM legater WHERE studie LIKE '%$u%'";
}
else if($s== "N" && $u != "0" && $k!="0") {
$query = "SELECT * FROM legater WHERE studie LIKE '%$u%' and kvartal LIKE '%$k%'";
}
else if($s== "N" && $u == "0" && $k!="0") {
$query = "SELECT * FROM legater WHERE kvartal LIKE '%$k%'";
}
else if($s!= "N" && $u == "0" && $k!="0") {
$query = "SELECT * FROM legater WHERE studiegrad LIKE '%$s%' and kvartal LIKE '%$k%'";
}
// Execute query
$result = mysql_query($query) or die ("Error in" . $query);
$number = mysql_num_rows($result);
// Check result
if ($number == 0) {
echo "Ingen legater fundet";
}
else {
while ($row = mysql_fetch_array($result)) {
echo "<li><a href=\"legat.php?id=" . $row['id'] . "\">" . $row['navn'] . "</a> </li>";
}
}
// free result set memory
mysql_free_result($result);
// close connection
mysql_close($connection);
Finally, this is my HTML header:
<meta charset="UTF-8">
I have no clue how to fix the characters. I have done the following:
- Checked that my Localhost (which I currently use for testing) uses UTF-8
- Made sure that my HTML has meta charset of UTF-8
- All my files are created in Notepad++ - I have made sure, that all files were properly created as UTF-8 (no BOM)
All help is very much appreciated!