在 IE 8 中使用 AJAX 发送 Unicode 字符
我有 IE 7 + 8 和页面,其中
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
我正在使用具有阿拉伯字符的 AJAX 发送字符串。
我的问题是到达服务器的字符串有??? IE 7 上的值和 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);
}
我怎样才能发送它来解决这个问题?
I have IE 7 + 8 and page which has
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
I'm sending string using AJAX which has Arabic character.
my problem is that the string which arrives to the server has ???? values on IE 7 and Gibrish on IE8. English chars are just fine.
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;
}
and then the AJAX itself:
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);
}
How can I send it solve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
替换
为
Replace
with
试试这个:
它对我有用。
try this :
It work for me.