Use XMLHTTP and ASP to Implement Asynchronous webpage calling

Source: Internet
Author: User

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.

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.