0

I have a simple XMLHttpRequest request

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(divID).innerHTML=xmlhttp.responseText;
 }
xmlhttp.open("GET","page.php?q="+str,true);
xmlhttp.send();

When I try to print text in the AJAX page (page.php) like é it returns something weird

echo "éééé";

However, if I use utf8_encode() it's all fine:

$string=utf8_encode("ééé");
echo $string;

Now my question is., how can I make this whole page utf8 ? I want to have my é correct without having to use utf8_encode() on every string I output. It's working on all my pages, except the ones in ajax. They are all like

<?php
session_start();
code
?>

There's no header defined, I tried

header('Content-Type: text/html; charset=utf-8');

but it's not working.

Nicolas.
  • 453
  • 1
  • 5
  • 27
  • 1
    Are you *sure* your content type is not coming back as UTF-8? (Hint: check firebug, or other header analyzer). This may help as well: http://stackoverflow.com/questions/8285936/how-to-change-ajax-charset – Rob W Jun 04 '13 at 21:04
  • Save your source file with utf-8 encoding. – Musa Jun 04 '13 at 21:42
  • @RobW fire bug is helpfull, thanks – Nicolas. Jun 04 '13 at 22:05

0 Answers0