xmlhttp的编码是utf8,你页面的编码最好为utf8,
如果不是,那么返回的字串要指定编码
php中用
header("Content-Type:text/html;charset=GB2312");另外不需要使用escape
使用encodeURIComponent("中文");就可以了,服务器端会自动解码
接收时也不必用unescape
如果不是,那么返回的字串要指定编码
php中用
header("Content-Type:text/html;charset=GB2312");另外不需要使用escape
使用encodeURIComponent("中文");就可以了,服务器端会自动解码
接收时也不必用unescape
查了很多资料说要用escape一下,
再用unescape回来就不会乱了,我的还是会乱。。有没有可以直接在我上面贴出的代码里控制编码的?
找到了一个JS的编码转换,好像没用。你们都是怎么整的这个?
大家看看得到的页面信息编码是utf-8的,显示为乱码,能否用js来改变其编码方式,不会显示乱码?
http://community.csdn.net/Expert/topic/4751/4751359.xml?temp=.3371546
相对于
http://community.csdn.net/Expert/topic/4748/4748452.xml?temp=.6224329巧妙避开了对中文问题的处理,改进后程序速度效率提高了几个数量级
为什么要unescape?
不能unescape,你可以用vbs将gbk转为utf8.由于服务器是别人的,所以你只能这么做。
request.responseText回来的不是utf-8的编码吗??我想有没有用js转换utf-8成gb2312的。Go_rush,如果我没有看错的话,你是取得中文部分再来转换的。
我这个是整个页面啊,是不是不同?
我直接COPY那个VBS的函数和reCode()来用,会出错,不知道有什么要求?
Javascrip基础比较差,如果能讲解一下就太感谢了。
2.如果服务器你不能修改代码,那就需要进行编码转换,这个只能用VBS做到
网上现在的代码
Function bytes2BSTR(vIn)
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
</script>
Dim strReturn()
j=LenB(vIn)
ReDim strReturn(j+1)
For i = 1 To j
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn(i) = Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn(i) = Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = Join(strReturn,"")
End Function
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD><BODY>
<script language="javascript" type="text/javascript"> var request = false;
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = false;
}
}
} if (!request)
alert("Error initializing XMLHttpRequest!"); function getCustomerInfo() {
var phone = document.getElementById("phone").value;
var url = "http://192.168.1.223/ajax/test.php?phone=" + escape(phone);
request.open("GET", url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
function getSalesData() {
var url = "http://192.168.1.223/ajax/test.php";
request.open("HEAD", url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
function postCustomerInfo() {
var key = document.getElementById("key").value;
var submit1 = document.getElementById("submit1").value;
var page = document.getElementById("page").value;
var url = "http://www.0577hr.com/search_.php";
var postUrl = "key=" + key + "&submit1=" + submit1 +"&page=" + page; request.open("POST", url, true);
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.onreadystatechange = updatePage;
request.send(postUrl);
} function updatePage() {
if (request.readyState == 4){
//alert(request.responseText);
var html1 = bytes2BSTR(request.responseBody);
html.document.open();
html.document.write( html1 );
html.document.close();
}
} function loading(){
html.document.open();
html.document.write( "Loading..." );
html.document.close();
}
</script><table border=0 cellspacing=1 cellpadding=1 bgcolo=eeeeee>
<tr>
<form name="pagesee" method="post">
<input type="hidden" id="key" value="where pubdate >= NOW() - INTERVAL 3 DAY && i_state != 2 && c_state !=2 ">
<input type="hidden" id="submit1" value="">
<td colspan=5 align=right><input type="text" id="page" value="1" size=5>
<input type=button onclick='loading();page.value--;postCustomerInfo();' value='PREV'> |
<input type=button onclick='loading();page.value++;postCustomerInfo();' value='NEXT'>
</td>
</form>
</tr>
</table>
<iframe id="html" name="html" src="" width="100%" height="400"></iframe>
<script language="vbs">
Function bytes2BSTR(vIn)
Dim strReturn()
j=LenB(vIn)
ReDim strReturn(j+1)
For i = 1 To j
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn(i) = Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn(i) = Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = Join(strReturn,"")
End Function</script>
</BODY>
</HTML>