<script language=javascript>
var ii=1;
var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
var oDoc = new ActiveXObject("MSXML2.DOMDocument");
var strUrl="http://www.XXXXXX.cn";
oHttpReq.open("Get", strUrl+"/rss/IndexList.aspx", false);
oHttpReq.send("");
result = oHttpReq.responseText;
oDoc.loadXML(result);
ID = oDoc.selectNodes("//DB/L/ID");
Title =oDoc.selectNodes("//DB/L/ProTitle");
Img=oDoc.selectNodes("//DB/L/vc_ImgPath");
for(i=0;i<ID.length;i++)
{
......
}
</script>
如上代码写完后在IE中查看G://s/Noname2.html查看一切正常 可当换到http://127.0.0.1:1011/s/Noname2.html时系统提示没权限访问 这才想到可能是javascript不能跨域名访问的问题 麻烦 但还是找到了解决方法
建立一个A.aspx文件
private void Page_Load(object sender, System.EventArgs e)
{
Response.Clear();
Response.AppendHeader("Content-type","text/xml;charset=GB2312");
System.Net.HttpWebResponse rs =(System.Net.HttpWebResponse)System.Net.HttpWebRequest.Create(Request["Url"]).GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(rs.GetResponseStream(), System.Text.Encoding.Default );
Response.Write(sr.ReadToEnd());
Response.End();
}
再修改Noname2.html文件
<script language=javascript>
var ii=1;
var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
var oDoc = new ActiveXObject("MSXML2.DOMDocument");
var strUrl="http://www.XXXXXX.cn";
oHttpReq.open("Get", "X.aspx?Url=http://www.XXXXXX.cn/IndexList.aspx", false);
oHttpReq.send("");
result = oHttpReq.responseText;
oDoc.loadXML(result);
ID = oDoc.selectNodes("//DB/L/ID");
Title =oDoc.selectNodes("//DB/L/ProTitle");
Img=oDoc.selectNodes("//DB/L/vc_ImgPath");
for(i=0;i<ID.length;i++)
{
......
}
</script>