Xml
The current ASP technology is more and more mature, most developers in the development of only using the ASP's own objects and database components to achieve client and Web server interaction. I now introduce two very useful components XmlDocument, XMLHTTP, and they can achieve several functions, I believe that the development of ASP can bring some new ideas.
Any development should be based on demand, we will not introduce these two components how to use, to see directly what they can do? In our
Use them to do some simple functions and get a deeper understanding of their various ways of using them.
Function One: Realize the local static refresh of the page
Suppose you want to display the current number of people online in the upper-right corner of all pages. The number of people currently online resides in the server's global variable application ("Online_num").
General methods:
1. Place an inside frame tag (<iframe>) in the upper-right corner and let him point to a new page new.asp, read in new.asp
The value of application ("Online_num") is displayed and refreshed at certain times.
Code:
Default.asp
...
<iframe width=20 height=5 src=new.asp border=0></iframe>
...
New.asp
<meta http-equiv= "Refresh" content= "1100;url=new.asp" >
<%
Response.Write "Current online number" & Application ("Online_num")
%>
Disadvantage: Because it is a page refresh, refresh will appear under the browser Blue status bar.
The New approach:
Also create a new file new.asp
New.asp
<%
Response.Write Application ("Online_num")
%>
Default.asp
<script language=vbscript>
Sub Getonlinenum ()
Dim Objxmlhttp,strreturn
Set Objxmlhttp=createobject ("MICROSOFT. XMLHTTP ")
Objxmlhttp.open "Get", "http://localhost:80/new.asp", False
Objxmlhttp.send ""
Strreturn=objxmlhttp.responsetext
Online_num.innerhtml= "Current online number" & Strreturn
SetTimeout ("Getonlinenum ()", 60000)
End Sub
</script>
<body onload=vbscript:getonlinenum () >
<span id=online_num></span>
...