错误显示泰语:

时间:2014-04-07 05:07:01

标签: javascript xmlhttprequest thai southeast-asian-languages

我有一个文件notfound.php,它会返回英语和泰语的可用关键字列表。 它包含

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

如果我使用我拥有的任何浏览器请求页面,那么泰语将正确显示,其中使用JavaScript调用同一文件时输出泰语错误。

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

此片段来自同时包含

的文件

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

返回“区域”的文字仅在Chrome中正确显示。

1 个答案:

答案 0 :(得分: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);
}