Javascript asynchronous page query implementation code (Asp.net)

Source: Internet
Author: User

1. Testlist. ASPX page: CopyCode The Code is as follows: <HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
<LINK rel = "stylesheet" href = "jscript/autosuggest.css" type = "text/CSS"/>
<LINK rel = "stylesheet" href = "jscript/ac.css" type = "text/CSS"/>
<Script language = "JavaScript" src = "jscript/autosuggest. js"> </SCRIPT>
<Script language = "JavaScript" src = "jscript/AC. js"> </SCRIPT>
Function acclient (queryurl, width, objinput, objlable)
{
This. xmldom = getxmlhttp ();
This. queryurl = queryurl;
This. prolist = new array ();
This. divwidth = width;
This. objinput = objinput;
This. geteligible = function (AC ){
VaR eligible = new array ();
If (AC. inputtext. Length <1 ){
Document. getelementbyid (objinput. Name). value = "";
Document. getelementbyid (objlable. Name). value = "";
Return eligible;
}
VaR strurl = This. queryurl + escape (AC. inputtext) + "& Rand =" + math. Random ();
This. xmldom. Open ("get", strurl, false );
Try {
This. xmldom. Send ();
}
Catch (e ){
Return;
}
This. prolist = this.xmldom.responsexml.doc umentelement. selectnodes ("/duxion/object ");
If (0 = This. prolist. Length ){
Return eligible;
}
For (VAR I = 0; I <this. prolist. length; I ++ ){
If (I> 15)
Break;
VaR node = This. prolist. item (I );
Eligible [eligible. Length] = node. getattribute ("fullcontent ");
}
AC. Div. style. width = This. divwidth;
Return eligible;
};
This. usesuggestion = function (SEL)
{
If (SEL> = 0)
{
VaR node = This. prolist. Item (SEL );
If (typeof (node. getattribute ("value "))! = "Undefined ")
Document. getelementbyid (objinput. Name). value = node. getattribute ("value ");
Else
Document. getelementbyid (objinput. Name). value = "";
If (typeof (node. getattribute ("content "))! = "Undefined ")
Document. getelementbyid (objlable. Name). value = node. getattribute ("content ");
Else
Document. getelementbyid (objlable. Name). value = "";
If (this. objinput. Name = "hidfreq_code "){
Document. getelementbyid ("txtfreq_name"). value = node. getattribute ("name ");
Document. getelementbyid ("hidfreq_code"). value = node. getattribute ("Code ");
}
}
};
Return this;
}
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<% -- Div is used to display the drop-down list -- %>
<Div id = "autosuggest" style = "width: 160px; font-size: 12px;"> <ul> </div>
<Div>
<Asp: textbox id = "txtfreq_name" cssclass = "needtext" runat = "server" width = "100px"> </ASP: textbox> <asp: hiddenfield
Id = "hidfreq_code" runat = "server"/>
</Div>
</Form>
</Body>
</Html>
<SCRIPT type = "text/JavaScript">
New autosuggest (document. getelementbyid ('txtfreq _ name '),
New acclient ("testxml. aspx? Tag = yp_frequency & value = "," 200px ", document. getelementbyid ('hidfreq _ Code'), document. getelementbyid ('txtfreq _ name ')));
</SCRIPT>

2. Testxml. aspx. CS file of the XML for query Copy code The Code is as follows: public partial class testxml: baseform
{
Protected void page_load (Object sender, eventargs E)
{
Listxmldata ();
}
Private string [] arrwidth;
Private string [] arrfield;
Public String fieldlist = "Region ID, Region name, region encoding, region level ";
Public String coloumwidth = "60, 10, 20, 30 ";
// Display XML format data
Private void listxmldata ()
{
// The width of each field
String strwhere = "";
If (request ["value"]! = NULL)
{
Strwhere = string. Format ("and code like '{0} %'", request ["value"]. tostring ());
}
Arrfield = fieldlist. Split (',');
Arrwidth = coloumwidth. Split (',');
Datatable dtlist = new districts (). Search ("1 = 1" + strwhere); // dis // sqlhelper. gettable (subsys_db, commandtype. Text, strsql, null );
Int list_cols = dtlist. Columns. Count; // number of fields
Int list_rows = dtlist. Rows. Count; // number of records
String listlable = ""; // display content
Xmldocument xmldoc = new xmldocument ();
Xmldeclaration dec = xmldoc. createxmldeclaration ("1.0", "gb2312", null );
Xmldoc. insertbefore (Dec, xmldoc. firstchild );
Xmlelement root = xmldoc. createelement ("duxion ");
Xmldoc. appendchild (Root );
// Display the header
If (list_rows> 0)
{
Xmlelement objtitle = xmldoc. createelement ("object ");
For (int K = 0; k <list_cols; k ++)
{
Listlable + = "<span style = 'width:" + arrwidth [k] + "; text-align: center; font-weight: bold; color: #000000; padding-top: 2px; '> "+ arrfield [k] +" </span> ";
If (k = arrfield. Length-1)
Break;
}
Objtitle. setattribute ("fullcontent", listlable );
Root. appendchild (objtitle );
}
// Display the header
// Display data
For (INT I = 0; I <list_rows; I ++)
{
Listlable = "";
Datarow drlist = dtlist. Rows [I];
Xmlelement OBJ = xmldoc. createelement ("object ");
For (Int J = 0; j <list_cols; j ++)
{
OBJ. setattribute (dtlist. Columns [J]. columnname, drlist [J]. tostring ());
If (j <= arrfield. Length-1)
{
// Listlable + = "<span style = 'width:" + arrwidth [J] + "'>" + getleftstring (drlist [J]. tostring (), convert. toint16 (arrwidth [J]) + "</span> ";
Listlable + = "<span style = 'width:" + arrwidth [J] + "'>" + formatxmlnode (dtlist. columns [J]. datatype. tostring (), drlist [J]. tostring () + "</span> ";
}
}
OBJ. setattribute ("fullcontent", listlable );
Root. appendchild (OBJ );
}
// Display data
// Response. contenttype = "text/XML; charset = UTF-8 ";
// Response. contenttype = "text/XML; charset = gb2312 ";
Response. contentencoding = system. Text. encoding. default;
Response. contenttype = "text/XML ";
Response. Clear ();
Response. Write (xmldoc. outerxml );
Response. End ();
}
Private string formatxmlnode (string field_type, string field_value)
{
String return_value = field_value.trim ();
Switch (field_type)
{
Case "system. Double ":
Case "system. Decimal ":
Return_value = string. Format ("{0: 0. ###}", convert. todouble (return_value ));
Break;
}
Return return_value;
}
}

3 .:

4. For other. js and. CSS files, see the attachment.

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.