我有IE 7 + 8和
的页面<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
我正在使用具有阿拉伯字符的AJAX发送字符串。
我的问题是到达服务器的字符串有???? IE8上的值和IE8上的Gibrish值。英语字符很好。
function getXmlHttpObject()
{
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
return xmlHttp;
}
然后是AJAX本身:
function updateName()
{
//updateLocal();
xmlHttp = getXmlHttpObject();
var username = document.getElementById('username').value;
xmlHttp.onreadystatechange=function(){onResponseUpdateOrderName();};
var params = "username=" +username;
xmlHttp.open("POST",myRootLink+"/myServlet/?"+params,true);
var boundaryString = 'bound';
var boundary = '--' + boundaryString;
var requestBody = [
boundary,
params,
boundary,
].join('\r\n');
xmlHttp.setRequestHeader("Content-length", requestBody.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.setRequestHeader('Content-type', 'text/xml;charset=utf-8');
xmlHttp.send(requestBody);
}
我如何发送它解决这个问题?
答案 0 :(得分:0)
替换
var params = "username=" +username;"
与
var params = "username=" +username;
答案 1 :(得分:0)
试试这个:
xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
它对我有用。