Tedious page refresh, greatly reducing the performance of webpage interaction. In the interaction between the server and the client, only a small amount of information needs to be transmitted, but a large amount of data has to be transferred and downloaded due to server refreshing. Here we will describe how to implement the new method without refreshing.
Suppose the effect is that when you select the drop-down column, the detailed information is not displayed.
The running idea is described as follows: double-click the line in the select control of the client. The client selects the line information and uses JavaScript statements and XMLHTTP controls to post the parameters to the server. The server accepts the parameters, execute the processing, pass the XML to the client, and then the client obtains the XML, parses, and binds the client control.
The client code is as follows:
Function showdata (){
VaR spagename = "accepted page. aspx ";
VaR objselect = Document. form1.selstation; // control selected by the client
VaR objchengqu = Document. getelementbyid ("txtdistrict"); // text box 1 of the server's information
VaR objpianqu = Document. getelementbyid ("txtarea"); // text box 2 of the server information
VaR objdonhge = Document. getelementbyid ("buildlist"); // select box for server information
VaR posturl = spagename + "? Selected = "+ objselect. Options [objselect. Options. selectedindex]. value;
// Construct the Transfer Path
VaR oxmlhttp = new activexobject ("msxml2.xmlhttp"); // call the XMLHTTP Control
Oxmlhttp. Open ("Post", posturl, false); // post to the server
Oxmlhttp. Send ("");
VaR result = oxmlhttp. responsetext; // get the returned result.
VaR odoc = new activexobject ("msxml2.domdocument"); // call the XML Control
Odoc. loadxml (result); // import XML
While (objdonhge. Options. length> 0)
{// Completely clear the content of the original select box
Objdonhge. Options. Remove (0 );
}
If (odoc. getelementsbytagname ("city"). length> = 1)
Objchengqu. value = odoc. getelementsbytagname ("city"). Item (0). text;
// Fill in text box 1
If (odoc. getelementsbytagname ("region"). length> = 1)
Objpianqu. value = odoc. getelementsbytagname ("region"). Item (0). text;
// Fill in text box 2
VaR maxnum_out = odoc. getelementsbytagname (""). length;
For (I = 0; I <maxnum_out; I ++ ){
VaR str1 = odoc. getelementsbytagname (""). Item (I). text;
VaR ooption = Document. createelement ("option ");
Objdonhge. Options. Add (ooption );
Ooption. innertext = str1;
Ooption. value = str1; // ID
} // Fill in drop-down box 2
}
The server code is as follows:
Private void page_load (Object sender, system. eventargs E)
{
If (request ["selected"]! = NULL)
{
Xmltextwriter writer = new xmltextwriter (response. outputstream, response. contentencoding );
Writer. Formatting = formatting. indented;
Writer. indentation = 6;
Writer. indentchar = '';
Writer. writestartelement (" ");
Writer. writeelementstring ("city", "Sunshine beach" + request ["selected"]);
Writer. writeelementstring ("area", "World Garden" + request ["selected"]);
Writer. writeelementstring ("Dong ge", request ["selected"] + "period ");
Writer. writeelementstring ("", request ["selected"] + "phase B ");
Writer. writeelementstring ("Dong ge", request ["selected"] + "Phase C ");
Writer. writeelementstring ("Dong ge", request ["selected"] + "period D ");
Writer. writeendelement (); // construct the XML
Writer. Flush ();
Response. End (); // end response
Writer. Close ();
}
}
A simple function can be implemented without any need. You can retrieve data from the database and construct XML as needed.