XMLHTTP Ajax for refreshing data

Source: Internet
Author: User

Function: when the focus of a text box is lost, other related information is displayed.
HTML:

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> untitled faces </title>
<SCRIPT type = "text/JavaScript" Language = "JavaScript">...
VaR XMLHTTP = false;
Function ajaxset ()
...{
If (window. XMLHttpRequest)
...{
XMLHTTP = new XMLHttpRequest;
}
Else
...{
Try
...{
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
Catch (E)
...{
XMLHTTP = new activexobject ("msxml2.xmlhttp ");
}
}
}
Function ajaxsendserver ()
...{
Ajaxset ();
VaR userid = Document. getelementbyid ("txtuserid"). value;
VaR url = "Dal. aspx? Id = "+ userid;
XMLHTTP. onreadystatechange = updatepage;
XMLHTTP. Open ("get", URL, true );
XMLHTTP. Send (null );
}
Function updatepage ()
...{
If (XMLHTTP. readystate = 4)
...{
If (XMLHTTP. Status = 200)
...{
VaR reponse = XMLHTTP. responsetext. Split (',');
Document. getelementbyid ("txtname"). value = reponse [0];
Document. getelementbyid ("txtdepart"). value = reponse [1];
XMLHTTP = false;
}
}
}

</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Input type = "text" id = "txtuserid" runat = "server" onfocusout = "ajaxsendserver ()"/>
<Asp: textbox id = "txtname" runat = "server"> </ASP: textbox>
<Asp: textbox id = "txtdepart" runat = "server"> </ASP: textbox>
<Asp: gridview id = "gvtest" runat = "server" width = "483px"> </ASP: gridview>
</Div>
</Form>
</Body>
</Html>

Data processing URL: Dal. aspx

Protected void page_load (Object sender, eventargs E)
...{
If (request. querystring [0]. tostring () = "f5400171 ")
...{
Service. WebService cdal = new WebService ();

String SQL = "select username, parameters no from userinfor where userid = '" + request. querystring [0]. tostring () + "'";

String S = cdal. getstr (SQL );

// String S = "jiaxin, mis ";
Response. Write (s );
Response. End ();
}
}

The data access is implemented using WebService, which is not described here ~

Related Article

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.