www.baike369.com
百科369 > Ajax教程 > XMLHttpRequest(XHR)对象制作www.baike369.com相关阅读实例

XMLHttpRequest(XHR)对象制作www.baike369.com相关阅读实例


XMLHttpRequest(XHR)对象制作www.baike369.com相关阅读实例

1. baike369_1.js的源代码如下:

document.writeln("<div class=cb id=\"main_M\">");
document.writeln("</div>");
function FF(y,x){
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
   if (!y) {
     y=1;
   } 
   var xmlhttp;
   if (window.ActiveXObject) {
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }else if(window.XMLHttpRequest)  {
      xmlhttp=new XMLHttpRequest();
   }
   if (xmlhttp) {
        xmlhttp.onreadystatechange=function () {
		  if(xmlhttp.readyState==4)  {
             if(xmlhttp.status==200)  {
	            var yy=unescape(xmlhttp.responseText);
				     show2(yy);
	         }else {
//		       alert("error");
	         }
          }
		}
if (window.location.host=="www.baike369.com"){
		if(!x){
if(!getQueryString("p")){
	    xmlhttp.open("get","http://www.baike369.com/include/baike369_1.asp?id="+getQueryString("id")+"&page="+y+"&urlname=baike369.com/content/");
}
else{
	    xmlhttp.open("get","http://www.baike369.com/include/baike369_1.asp?id="+getQueryString("id")+"&p="+getQueryString("p")+"&page="+y+"&urlname=baike369.com/content/");
}
		}
		else
		{
if(!getQueryString("p")){
	    xmlhttp.open("get","http://www.baike369.com/include/baike369_1.asp?id="+getQueryString("id")+"&page="+y+"&kid="+x+"&urlname=baike369.com/content/");
}
else{
	    xmlhttp.open("get","http://www.baike369.com/include/baike369_1.asp?id="+getQueryString("id")+"&p="+getQueryString("p")+"&page="+y+"&kid="+x+"&urlname=baike369.com/content/");
}
		}
}
if (window.location.host=="baike369.com"){
		if(!x){
if(!getQueryString("p")){
	    xmlhttp.open("get","http://baike369.com/include/baike369_1.asp?id="+getQueryString("id")+"&page="+y+"&urlname=baike369.com/content/");
}
else{
	    xmlhttp.open("get","http://baike369.com/include/baike369_1.asp?id="+getQueryString("id")+"&p="+getQueryString("p")+"&page="+y+"&urlname=baike369.com/content/");
}
		}
		else
		{
if(!getQueryString("p")){
	    xmlhttp.open("get","http://baike369.com/include/baike369_1.asp?id="+getQueryString("id")+"&page="+y+"&kid="+x+"&urlname=baike369.com/content/");
}
else{
	    xmlhttp.open("get","http://baike369.com/include/baike369_1.asp?id="+getQueryString("id")+"&p="+getQueryString("p")+"&page="+y+"&kid="+x+"&urlname=baike369.com/content/");
}
		}
}
		xmlhttp.send(null);
    }		
}
function show2(text) {
document.getElementById("main_M").innerHTML=text;
}
window.onLoad=FF();

2. baike369_1.asp的源代码如下:

<%@LANGUAGE="VBSCRIPT" CODEPage="936"%>
<!--#include file="需要自己添加数据库表"-->
<%if Request.ServerVariables("HTTP_HOST")="www.baike369.com" or Request.ServerVariables("HTTP_HOST")="baike369.com" then
if Instr(Request.ServerVariables("HTTP_REFERER"),"baike369.com/content/?id=")>0 or Instr(Request.ServerVariables("HTTP_REFERER"),"baike369.com/content/default.asp?id=")>0 then
if Request.QueryString("id")<>"" then
set linkd = Server.CreateObject("adodb.recordset")
set link = Server.CreateObject("adodb.recordset")
set cata = Server.CreateObject("adodb.recordset")
set cata2 = Server.CreateObject("adodb.recordset")
set linkd3 = Server.CreateObject("adodb.recordset")
linkid=Request.QueryString("id")
if Request.QueryString("p")&""<>"" then
'数据表名称需要自己修改
catasql = "SELECT Title,ID,content FROM baike369content where LinkID="&linkid&" and Pid="&Request.QueryString("p")&";"
else
catasql = "SELECT Title,ID,content FROM baike369content where LinkID="&linkid&";"
end if
set cata = connect.Execute (catasql)
If not cata.EOF then
muluid=cata("ID")
title=cata("Title")
contt=cata("content")
contt=replace(contt,"&quot;","""")
if Instr(contt,"&lt;!DOCTYPE html")>0 then
a1=Instr(contt,"&lt;!DOCTYPE html")
if Instr(a1,contt,""" /&gt;")>0 then
b1=Instr(a1,contt,""" /&gt;")
c1=Mid(contt,a1,b1-a1)
contt=replace(contt,c1,"")
end if
end if
sqlstrd3 = "SELECT tagkey FROM baike369tags where ID="&muluid&" and automark is not null;"
set linkd3 = connect.Execute(sqlstrd3)
If not linkd3.EOF then
do until linkd3.EOF
tagkeynot=replace(linkd3("tagkey"),"&quot;","""")
if InStr(tagkeynot,"&lt;")>0 then
tagkeynot=replace(replace(tagkeynot,"&lt;","<"),"&gt;",">")
end if
if InStr(tagkeynot,"&lltt;")>0 then
tagkeynot=replace(replace(tagkeynot,"&lltt;","&lt;"),"&ggtt;","&gt;")
end if
title=replace(title,tagkeynot,"")
title=replace(title,UCase(tagkeynot),"")
title=replace(title,LCase(tagkeynot),"")
linkd3.movenext
loop
linkd3.movefirst
do until linkd3.EOF
tagkeynot=replace(linkd3("tagkey"),"&quot;","""")
if InStr(tagkeynot,"&lt;")>0 then
tagkeynot=replace(replace(tagkeynot,"&lt;","<"),"&gt;",">")
end if
if InStr(tagkeynot,"&lltt;")>0 then
tagkeynot=replace(replace(tagkeynot,"&lltt;","&lt;"),"&ggtt;","&gt;")
end if
contt=replace(contt,tagkeynot,"")
contt=replace(contt,UCase(tagkeynot),"")
contt=replace(contt,LCase(tagkeynot),"")
linkd3.movenext
loop
end if
end if
tky=""
sqlstrd3 = "SELECT KID,tagkey FROM baike369tags where ID="&muluid&" and automark is null;"
set linkd3 = connect.Execute(sqlstrd3)
If not linkd3.EOF then
do until linkd3.EOF
if InStr(title,linkd3("tagkey"))>0 or InStr(title,UCase(linkd3("tagkey")))>0 or InStr(title,LCase(linkd3("tagkey")))>0 or InStr(UCase(title),linkd3("tagkey"))>0 or InStr(UCase(title),UCase(linkd3("tagkey")))>0 or InStr(LCase(title),linkd3("tagkey"))>0 or InStr(LCase(title),LCase(linkd3("tagkey")))>0 or InStr(contt,linkd3("tagkey"))>0 or InStr(contt,UCase(linkd3("tagkey")))>0 or InStr(contt,LCase(linkd3("tagkey")))>0 or InStr(UCase(contt),linkd3("tagkey"))>0 or InStr(UCase(contt),UCase(linkd3("tagkey")))>0 or InStr(UCase(contt),LCase(linkd3("tagkey")))>0 or InStr(LCase(contt),linkd3("tagkey"))>0 or InStr(LCase(contt),LCase(linkd3("tagkey")))>0 or InStr(LCase(contt),UCase(linkd3("tagkey")))>0 then
tky=tky&"bbbbb"&linkd3("tagkey")&"KKKKK"&linkd3("kid")
end if
linkd3.movenext
loop
end if
if tky&""<>"" then%><!--#include file="baike369_1_01.asp"--><%end if
if Request.QueryString("kid")&""<>"" then
cata2sql = "SELECT tagkey FROM baike369tags where KID="&Request.QueryString("kid")&";"
set cata2=connect.Execute(cata2sql)
If not cata2.EOF then
  tagkey=cata2("tagkey")
strsql="select Title,LinkID,Pid FROM baike369content where (Title LIKE '%"&tagkey&"%' or Title LIKE '%"&UCase(tagkey)&"%' or Title LIKE '%"&LCase(tagkey)&"%') and ID="&muluid&" and LinkID<>"&linkid&" order by LinkID DESC;"
end if
else
strsql="select top 200 Title,LinkID,Pid FROM baike369content where ID="&muluid&" and LinkID<>"&linkid&" order by LinkID DESC;"
end if
link.source=StrSQL
link.ActiveConnection=connect
link.CursorType=3
link.Open
link.PageSize=10
If not link.EOF then
if Request("Page")="" then
Page=1
else
Page=CInt(Request("Page"))
end if
link.AbsolutePage=Page
Response.Write "<div class=read><ul>"
for i=1 to link.PageSize
if link("Pid")=1 then
Response.Write "<li>&middot;<a href="&escape("http://www.baike369.com")&"/content/?id="&link("LinkID")&" target=_blank>"&escape(link("Title"))&"</a></li>"
else
Response.Write "<li>&middot;<a href="&escape("http://www.baike369.com")&"/content/?id="&link("LinkID")&"&p="&link("Pid")&" target=_blank>"&escape(link("Title"))&escape("(第")&link("Pid")&escape("页)")&"</a></li>"
end if
link.movenext
if link.EOF then
  Exit for
end if         
next
Response.Write "</ul></div>"
if Request.QueryString("kid")&""="" then
%><!--#include file="baike369_1_03.asp"--><%else
%><!--#include file="baike369_1_04.asp"--><%end if
response.Write "<div class=md></div>"
end if
else
Response.Status ="404"
Server.Execute("/__ErrFiles__/404.html")
Response.end
end if
else
Response.Status ="404"
Server.Execute("/__ErrFiles__/404.html")
Response.end
end if
else
Response.Status ="404"
Server.Execute("/__ErrFiles__/404.html")
Response.end
end if%>

3. baike369_1_01.asp文件的源代码如下:

<%Response.Write("<div class=read><h2>"&escape("相关阅读")&"</h2></div>")
Response.Write("<div class=read><div class=""table2"">")
keytag=split(tky,"bbbbb")
tnum=ubound(keytag)
a=0
for tn=1 to tnum+1
a=a+1
  tt=keytag(tn-1)
  if InStr(tt,"KKKKK")>0 then
  tt2=Mid(tt,InStr(tt,"KKKKK"))
  tt2=replace(tt2,"KKKKK","")
  tt3=replace(replace(tt,tt2,""),"KKKKK","")
link2sql="select top 1 LinkID FROM baike369content where (Title LIKE '%"&tt3&"%' or Title LIKE '%"&UCase(tt3)&"%' or Title LIKE '%"&LCase(tt3)&"%') and ID="&muluid&" and LinkID<>"&linkid&";"
set link2=connect.Execute(link2sql)
If not link2.EOF then
if tt2=Request.QueryString("kid") then
  response.Write("<a href='javascript:FF(1,"&tt2&")'><div style=background:#468ED0;display:inline;padding:5px 10px;>"&escape(tt3)&"</div></a>  ")
else
if a=tnum+1 then
  response.Write("<a href='javascript:FF(1,"&tt2&")'>"&escape(tt3)&"</a>")
else
  response.Write("<a href='javascript:FF(1,"&tt2&")'>"&escape(tt3)&"</a>  ")
end if
end if
end if
end if
next
Response.Write("</div></div>")%>

4. baike369_1_03.asp文档的源代码如下:

<%if link.PageCount>1 then
response.Write("<div class=read><div class=""page""><div id=""pageNumN"">")
if Page>1 then
response.Write("<a href='javascript:FF(1)'>"&escape("首页")&"</a> ")
if Page=2 then
response.Write("<a href='javascript:FF("&(Page-1)&")'>"&escape("上页")&"</a> ")
else
response.Write("<a href='javascript:FF("&(Page-1)&")'>"&escape("上页")&"</a> ")
end if
end if
for bp=1 to link.PageCount
 if Page-bp<5 then
   While bp<Page+4 and bp=<link.PageCount
   if Page=bp then
	response.Write "<span class=""curPage"">"&Page&"</span>"
   else
    if bp=1 then
      response.Write "<a href='javascript:FF("&bp&")'>"&bp&"</a> "
	else
      response.Write "<a href='javascript:FF("&bp&")'>"&bp&"</a> "
	end if
   end if
    bp=bp+1
   Wend
  end if
 if Page-bp>=5 then
  bp=Page-5
  if Page+4 =< link.pageCount then
  While bp<Page+4
   if Page=bp then
	response.Write "<span class=""curPage"">"&Page&"</span>"
   end if
   if Page<>bp then
      response.Write "<a href='javascript:FF("&bp&")'>"&bp&"</a> "
   end if
    bp=bp+1
   Wend
  end if
  if Page+4 > link.pageCount then
  While bp =< link.pageCount
   if Page=bp then
	response.Write "<span class=""curPage"">"&Page&"</span>"
   end if
   if Page<>bp then
      response.Write "<a href='javascript:FF("&bp&")'>"&bp&"</a> "
   end if
    bp=bp+1
   Wend
  end if
 end if
next
if Page<link.PageCount then
  response.Write "<a href='javascript:FF("&(Page+1)&")'>"&escape("下页")&"</a> "
  response.Write "<a href='javascript:FF("&link.Pagecount&")'>"&escape("尾页")&"</a>"
end if
response.Write "<span class=""sumPage"">"&escape("共")&"<cite>"&link.PageCount&"</cite>"&escape("页")&"</span>"
response.Write("</div></div></div>")
end if%>

5. baike369_1_04.asp的源代码如下:

<%if link.PageCount>1 then
response.Write("<div class=read><div class=""page""><div id=""pageNumN"">")
if Page>1 then
response.Write("<a href='javascript:FF(1,"&Request.QueryString("kid")&")'>"&escape("首页")&"</a> ")
if Page=2 then
response.Write("<a href='javascript:FF("&(Page-1)&","&Request.QueryString("kid")&")'>"&escape("上页")&"</a> ")
else
response.Write("<a href='javascript:FF("&(Page-1)&","&Request.QueryString("kid")&")'>"&escape("上页")&"</a> ")
end if
end if
for bp=1 to link.PageCount
 if Page-bp<5 then
   While bp<Page+4 and bp=<link.PageCount
   if Page=bp then
	response.Write "<span class=""curPage"">"&Page&"</span>"
   else
    if bp=1 then
      response.Write "<a href='javascript:FF("&bp&","&Request.QueryString("kid")&")'>"&bp&"</a> "
	else
      response.Write "<a href='javascript:FF("&bp&","&Request.QueryString("kid")&")'>"&bp&"</a> "
	end if
   end if
    bp=bp+1
   Wend
  end if
 if Page-bp>=5 then
  bp=Page-5
  if Page+4 =< link.pageCount then
  While bp<Page+4
   if Page=bp then
	response.Write "<span class=""curPage"">"&Page&"</span>"
   end if
   if Page<>bp then
      response.Write "<a href='javascript:FF("&bp&","&Request.QueryString("kid")&")'>"&bp&"</a> "
   end if
    bp=bp+1
   Wend
  end if
  if Page+4 > link.pageCount then
  While bp =< link.pageCount
   if Page=bp then
	response.Write "<span class=""curPage"">"&Page&"</span>"
   end if
   if Page<>bp then
      response.Write "<a href='javascript:FF("&bp&","&Request.QueryString("kid")&")'>"&bp&"</a> "
   end if
    bp=bp+1
   Wend
  end if
 end if
next
if Page<link.PageCount then
  response.Write "<a href='javascript:FF("&(Page+1)&","&Request.QueryString("kid")&")'>"&escape("下页")&"</a> "
  response.Write "<a href='javascript:FF("&link.Pagecount&","&Request.QueryString("kid")&")'>"&escape("尾页")&"</a>"
end if
response.Write "<span class=""sumPage"">"&escape("共")&"<cite>"&link.PageCount&"</cite>"&escape("页")&"</span>"
response.Write("</div></div></div>")
end if%>
Copyright© 2011-2016 www.baike369.com All Rights Reserved