Through the combination of XMLHTTP and ASP, we can easily complete asynchronous webpage calls.
CodeAs follows:
1. Create display. asp (this is the front-end display page)
Note the four attributes of 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.doc umentelement. selectsinglenode ("// objxml"). Text)
VaR getinfo = xmldom.doc umentelement. selectsinglenode ("// objxml"). text;
Divtest. innerhtml = getinfo
}
}
</SCRIPT>
<Body>
<Input type = text id = txtinput>
<Input type = button value = "Asynchronous call" onclick = "fndo(document.all.txt input. Value)">
<Div id = divtest> </div>
<P> </P>
</Body>
</Html>
2. Create 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 the display. ASP page, enter the content in the text box, and click the button to view the loading prompt. Then, the content in the text box is obtained without refreshing the page. Of course, you can also perform some complicated operations based on the sent parameters on the getinfo. ASP page, and then return the results.