Javascript XMLHttpRequest可以';t发送unicode字符作为请求头
我想通过JavaScript发送XMLHttpRequest,一切正常。但当我尝试发送波斯语字符串而不是英语时,我遇到了以下错误:Javascript XMLHttpRequest可以';t发送unicode字符作为请求头,javascript,html,xmlhttprequest,Javascript,Html,Xmlhttprequest,我想通过JavaScript发送XMLHttpRequest,一切正常。但当我尝试发送波斯语字符串而不是英语时,我遇到了以下错误: TypeError: Cannot convert string to ByteString because the character at index 0 has value 1587 which is greater than 255. 请注意,这个错误只出现在Firefox和Chrome上,但在IE上一切正常。 这是我的代码片段: var xmlhttp;
TypeError: Cannot convert string to ByteString because the character at index 0 has value 1587 which is greater than 255.
请注意,这个错误只出现在Firefox和Chrome上,但在IE上一切正常。
这是我的代码片段:
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.setRequestHeader("serviceName", "سیبس"); // The line that cause of error
您可以将数据编码成类似base64的格式,并在服务器上对其进行解码
谢谢你的回答,我用uri编码和解码解决了这个问题。我认为base64也可以。