Using XMLHTTP combined with ASP to implement asynchronous call of Web page

Source: Internet
Author: User
With the combination of XMLHTTP and ASP, we can easily complete the asynchronous invocation of the Web page.
The code is as follows:
1. New Display.asp (This is the foreground display page)
Note the 4 properties of the Xmlhttp.readystate
1:loading;2:loaded;3:interactive;4:completed
<%@ Language=vbscript%>
<HTML>
<HEAD>
<meta name= "generator" content= "Microsoft Visual Studio 6.0" >
</HEAD>
<script language= "JavaScript" >
XMLHTTP = new ActiveXObject ("Msxml2.xmlhttp");
function Fndo (ID)
{
var xmldom = new ActiveXObject ("Msxml2.domdocument"); var strURL = "getinfo.asp?id=" + ID;
xmlHTTP. Open ("POST", strURL, True);
Xmlhttp.onreadystatechange = Fnrun;
xmlHTTP. Send (XMLDOM);
divtest.innerhtml = "Loading ..."
}
//--------------------------------------------------------
function Fnrun ()
{
var state = Xmlhttp.readystate;
var xmldom = new ActiveXObject ("Msxml2.domdocument");
if (state = = 4)
{
XMLDOM.loadXML (Xmlhttp.responseXML.xml);
Alert (XmlDom.documentElement.selectSingleNode ("//objxml"). Text)
var getInfo = XmlDom.documentElement.selectSingleNode ("//objxml"). Text;
divtest.innerhtml = GetInfo
} }
</script>
<BODY>
<input Type=button value= Asynchronous Call onclick= Fndo (Document.all.txtInput.value) >
<input Type=text id=txtinput>
<div id=divtest></div>
<P> </P>
</BODY>
</HTML>
2. In the establishment of getinfo.asp (this is the background processing page)
<%
Dim Sid,objresult
SID = Trim (Request ("ID")
' SID = 28
Set Objresult = Server.CreateObject ("MSXML2. DOMDocument ")
Objresult.loadxml ("<objXML></objXML>")
'**************************************************************

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.