3
By ajax, I am making a query the Database, but if the field has special characters, they appear badly. I am ordering in the following JS function, the result is shown in a div with 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 ajax/getproducts_section.php document 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);
?>
Everything works fine, I just have the problem of special characters appearing wrong. How can I get around this issue?
The base charset is utf8?
– rray
yes, the whole page is in utf-8, minus the value returned by ajax
– pc_oc