0

我有一个文件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 中正确显示。

4

1 回答 1

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);
}
于 2014-04-07T05:12:43.673 回答