我得把日文的名字寄给XMLHttpRequest。但它显示了编码问题..。我的tpl页面在utf-8字符集中。
这是我的密码。
function getFormData(dno,rno) {
var name = document.getElementById("f_nickname").value;
var digNo = dno;
var resNo = rno;
var strVal = digNo + "-" + resNo;
stp.push(strVal);
var xhr = new XMLHttpRequest();
if (!xhr) return false;
var url = 'ajax.php' + '?prc=' + 'diagnoses' + '&name=' + name + '&diagres=' + stp;
xhr.open('POST', url, true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send(stp);
return true;
}
我有这样经过的网址:
http://crp.com/ajax.php?prc=diagnoses&name=大阪&diagres=0-0,1-3,2-2,3-3,4-3,5-2
但它显示在Ajax.php中,如
http://crp.com/ajax.php?prc=diagnoses&name=ƒsƒU&diagres=0-0,1-3,2-2,3-3,4-3,5-2
尝试了很多方面..。怎么解决?提前谢谢..。
发布于 2015-11-04 11:29:42
在url中对这样的参数使用encodeURIComponent
。
var url = 'ajax.php' + '?prc=' + 'diagnoses' + '&name=' + encodeURIComponent(name) + '&diagres=' + stp;
它将导致url,例如:
http://crp.com/ajax.php?prc=diagnoses&name=%E5%A4%A7%E9%98%AA&diagres=0-0,1-3,2-2,3-3,4-3,5-2
而webserver会正确地处理它。
发布于 2015-11-04 11:25:07
试着添加:
xmlHttp.setRequestHeader('Content-type', 'text/xml;charset=utf-8');
使用:
encodeURIComponent(name)
而不仅仅是name
https://stackoverflow.com/questions/33520558
复制相似问题