解决AJAX中文乱码的N种方法

<SCRIPT language="VBScript" type="text/VBScript">
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 + 1
End If
Next
bytes2BSTR 
= strReturn
End Function
</script>

<script language="javascript"> 
function GetData() 

loadcontent.innerText
=getDatal("http://bbs.51js.com/index.php")
setTimeout(
"GetData()",1000); 
}

function getDatal(url){  
    
var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP.4.0");
    xmlhttp.open(
"post",url,false);   
    xmlhttp.send();              
    
return bytes2BSTR(xmlhttp.responsebody);       
    xmlhttp
=nothing
}  
</script>
<BODY onload="javascript:GetData();"> 
<span id="loadcontent">数据载入中……</span> 
</BODY> 




--------------------------------------------
<body text=green bgcolor=black></body><script>
down
=new ActiveXObject("downloadBehavior.downloadBehavior");
down.startDownload(
"http://bbs.51js.com/index.php",GetData);
function GetData(source)
{
    document.body.innerText
=source;
}
</script>
---------------------------------------------------------

<body text=00ff00 bgcolor=black></body><script>
xml
=new ActiveXObject("Microsoft.XmlHttp");
rs
=new ActiveXObject("ADODB.RecordSet");
xml.open(
"GET","index.php",false,"","");
xml.send();
rs.fields.append(
"a",201,1);
rs.open();
rs.addNew();
rs(
0).appendChunk(xml.responseBody);
rs.update();
document.body.innerText
=rs("a").value;
rs.close();
document.charset
="gbk";
</script>
---------------------------------------------------------

<body></body><script>
document.body.addBehavior(
"#default#Download");
document.body.startDownload(
"index.php",GetData);
function GetData(source)
{
    document.body.innerText
=source;
}
</script>
------------------------------------------------
个人认为如果只是传输数据的话建议采用Xml:
<script>
var xml=document.createElement("xml");
xml.async
=0;
xml.load(
"rss.php");
document.write(
"<plaintext>"+xml.xml);
</script>
-------------------------------
posted @ 2008-08-12 14:39  王其荣的博客  阅读(1071)  评论(0编辑  收藏  举报