蓝森林首页 | 返回主页 | 本站地图 | 站内搜索 | 联系信箱 |
 您目前的位置:首页 > 自由软件 > 技术交流 > 应用编程


    

蓝森林 http://www.lslnet.com 2006年8月25日 8:28

js用xmlHttp读出来网页是乱码.求朋友们帮忙解决.

实在是不会AJAX这类的东东,自己想了半天也解决不了乱码的问题.
还有另外一点在js里如果得到当前的URL~
就像http://www.golf998.com/Get/gdqc/14034744.htm
如果会的帮我写一个alert(URL)谢谢!

[html]<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>iframe_xml</title>
<style type="text/css">
<!--
body,td,th {
        font-size: 12px;
        font-family: Arial, Helvetica, sans-serif;
}
body {
        margin-left: 0px;
        margin-top: 0px;
        margin-right: 0px;
        margin-bottom: 0px;
}
-->
</style>
</head>

<body>
<iframe id="momoca" width="100%" height="100%"></iframe>
<script>

var xmlHttp = false;
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

function callServer() {
  var url = "http://www.golf998.com/Get/gdqc/14034744.htm";
  //xmlHTTP.setRequestHeader("Contrn-charset","gb2312");
  xmlHttp.open("GET", url, true);
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
  xmlHttp.setRequestHeader("Content-Type", "text/html;charset=GB2312");
  xmlHttp.onreadystatechange = updatePage;
  //xmlHttp.setRequestHeader("Content-Type", "text/html;charset=gb2312");
  //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
  //xmlHttp.onreadystatechange = updatePage;
  xmlHttp.send(null);  
}

function updatePage() {
  if (xmlHttp.readyState < 4) {
        initHTML="loading...";
  }
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
        initHTML=response;
  }
}
callServer()
momoca.document.designMode="ON";
momoca.document.open();
momoca.document.write(initHTML);
momoca.document.close();
</script>
</body>
</html>
[/html]

感觉经典上的人少了哦.都没有人理我了.哎...
自己给解决了.

[HTML]<style type="text/css">
<!--
body,td,th {
        font-family: Arial, Helvetica, sans-serif;
        font-size: 12px;
}
body {
        margin-left: 0px;
        margin-top: 0px;
        margin-right: 0px;
        margin-bottom: 0px;
}
-->

</style>
<title>bate 2 页面读取改进版Yeah... UpDate1:2006-8-11 14:3:11 | UpDate2:2006-8-11 14:8:26 | By momoca</title>
<input type="text" id="url" name="url" style="width:97%; " value="http://www.golf998.com/Get/gdqc/14034744.htm" onclick="this.value=''">
<input type="button"  onClick="momoca(url.value);" value="go" style="color:#FF0000;" onmousemove="document.all.momoca_write.innerHTML='您现在只要点击一下<font color=red>Go</font>就可以载入需要的网页了<br>loading...<br>页面载入中请等待...';">
<SCRIPT LANGUAGE="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 = i + 1
        End If
    Next
    bytes2BSTR = strReturn
End Function

Function momoca(url)
dim XmlHttp
set XmlHttp = CreateObject("Microsoft.XMLHTTP")
XmlHttp.Open "GET", url, false
XmlHttp.setRequestHeader "Content-Type","text/XML"

If xmlHttp.readyState < 4 then
document.all.momoca_write.innerHTML="loading...<br>页面载入中请等待..."
End If

XmlHttp.Send

If xmlHttp.readyState = 4 then
alert("页面载入成功 —— by momcoa")
End If

dim html
html = bytes2BSTR(XmlHttp.responseBody)
document.all.momoca_write.innerHTML=html
End Function
</script>
<div id=momoca_write></div>[/HTML]




Copyright © 1999-2000 LSLNET.COM. All rights reserved. 蓝森林网站 版权所有。 E-mail : webmaster@lslnet.com