By ajax, I am querying the Database, but if the field has special characters, they appear wrong. I'm making the request in the following JS function, the result is shown in a div with the id="txtHint"
<script charset="UTF-8">
function getProdutosSeccao(){
var idSeccao = $('#id_seccao').val();
if (idSeccao=="") {
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","ajax/getprodutos_seccao.php?q="+idSeccao,true);
xmlhttp.send();
}
</script>
In the document ajax / getprodutos_seccao.php I have the following:
<?php
$q = intval($_GET['q']);
require("ligar_ajax.php");
$sql = "SELECT * FROM tbl_produtos WHERE id_seccao = '".$q."'";
$result = mysqli_query($con,$sql);
echo '<select name="id_produto" style="width: 100%;" id="id_produto">';
while($row = mysqli_fetch_array($result)) {
echo "<option value='".$row['id_produto']."'>".$row['nome']."</option>";
}
echo "</select>";
mysqli_close($con);
?>
It works fine, I only have the problem that the special characters appear wrong. How can I get around this?