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 ~