The use of XMLHTTP components in ASP development

Source: Internet
Author: User
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>
...


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.