xml| Web page | asynchronous
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" >
<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>")
'**************************************************************
'**************************************************************
Objresult.selectsinglenode ("Objxml"). Text = "Get:" & SID
Response.ContentType = "Text/xml"
Objresult.save (Response)
Response.End
Set Objsch = Nothing
Set Objresult = Nothing
%>
3. Run Display.asp page, enter the content in the text box, click on the button, you can see the loading of the prompts, and then the page does not refresh the case of the text box to get the content. Of course, you can also do some complex work on the Getinfo.asp page based on the parameters you send, and then return the results.