Through the combination of xmlHttp and ASP, we can easily complete asynchronous calls to web pages.
The code is as follows:
1. Create a new Display.asp (this is the front-end display page)
Pay attention to the 4 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.documentElement.selectSingleNode(//objXML).text)
var getInfo = xmlDom.documentElement.selectSingleNode(//objXML).text;
divTest.innerHTML = getInfo
}
}
</script>
<BODY>
<input type=text id=txtInput>
<input type=button value=Asynchronous call onclick=fnDo(document.all.txtInput.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 content in the text box, click the button, you can see the Loading prompt, and then get the content in the text box without refreshing the page. Of course, you can also do some complicated calculations based on the parameters sent in the GetInfo.asp page, and then return the results.