0

I have a file notfound.php which returns a list of available keywords in English and Thai. It contains

meta http-equiv='Content-Type content='text/html; charset=tis-620'".

Thai Language displays properly if I request the page using any of the browsers I have, where outputs Thai wrongly when calling the same file using JavaScript.

document.getElementById("area").innerHTML=xmlhttp.responseText;
xmlhttp.open("GET","notfound.php?&mat=" + Math.random(),true);
xmlhttp.send();

This fragment is from a file also containing

meta http-equiv='Content-Type' content='text/html; charset=tis-620'.

The text returned to "area" displays correctly only in Chrome.

hippietrail
  • 15,848
  • 18
  • 99
  • 158
alberto
  • 115
  • 4
  • 19

1 Answers1

0
function sendByAJAX() {
   // get the user text and make it safe for HTTP transmission
   var userTxt = encodeURIComponent( document.getElementById('userTxt').value );
   // create the AJAX object
   var xmlhttp = new XMLHttpRequest();
   // assume successful response -- do NOT actually make this assumption in real code
   xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState==4 && xmlhttp.status>=200 && xmlhttp.status<300) {
         // You'll probably want to do something more meaningful than an alert dialog
         alert('POST Reply returned: status=[' + xmlhttp.status + 
        ' ' + xmlhttp.statusText + ']\n\nPage data:\n' + xmlhttp.responseText);
      }
   }
   xmlhttp.open('POST', 'http://www.site.com/submit/path');
   // here we are overriding the default AJAX type, 
   // which is UTF-8 -- this probably seems like a stupid thing to do
   xmlhttp.setRequestHeader('Content-type', 
    'application/x-www-form-urlencoded; charset=tis-620;');
   xmlhttp.setRequestHeader('User-agent'  , 'Mozilla/4.0 (compatible) Naruki');
   xmlhttp.send(userTxt);
}
Anand Natarajan
  • 1,172
  • 8
  • 7
  • changed get to post as for you suggested. Same: correct only in Chrome – alberto Apr 07 '14 at 05:36
  • I have tried xmlhttp.overrideMimeType("text/plain; charset=tis-620").It works in most browser,and thai text is now correct,but does not work in IE9 which complains 'overrideMimeType not a property of this object. – alberto Apr 07 '14 at 09:09
  • Spent the whole afternoon on this one. To make xmlhttp display Thai language correctly all request to server (GET/POST never mind) must have a php header in the requested file: header("Content-type: text/xml; charset=tis-620") at the very top line after the – alberto Apr 07 '14 at 12:00