<script language=javascript>
<!--
function GetSource( url, DestObj )
{
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
try
{
xmlhttp.onreadystatechange = function(){
if( xmlhttp.readyState == 4 )
{
if( xmlhttp.status == 200 )
{
DestObj.innerHTML = Bytes2BSTR( xmlhttp.responseBody );
if( xmlhttp.responseText == "" )
{
DestObj.innerText = "错误的服务";
}
}
else
{
DestObj.innerText = "由于网络状况导致服务失败";
}
}
else
{
DestObj.innerText = "服务加载中
";
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
catch(ex)
{
DestObj.innerText = "加载错误!";
}
}
GetSource("weather.asp?id=" + Math.random(), document.getElementById("cnweather"));
//-->
</script>
<script language=vbscript>
Function Bytes2BSTR( vIn )
Dim strReturn
Dim i
i = 0
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>
无刷新获取天气预报的代码实现
博客给出了一段无刷新获取天气预报的代码。通过 JavaScript 创建 XMLHTTP 对象,尝试从指定 URL 获取数据,根据不同状态更新目标对象内容。还包含 VBScript 函数用于处理字节数据。代码可实现无刷新偷取天气预报信息。
145

被折叠的 条评论
为什么被折叠?



