Partial Ajax refresh

Source: Internet
Author: User
Ajax implements partial refresh <SCRIPT type = "text/JavaScript"> var XMLHTTP; function getdata () {// obtain the name specified by the user var city = document. getelementbyidx ("TXT "). value; // create an asynchronous call object XMLHTTP = new activexobject ("Microsoft. XMLHTTP "); // associate the object state with the event XMLHTTP. onreadystatechange = statechange; // load the page to be linked XMLHTTP. open ("Post", "datapage. aspx? City = "+ city, true); // sends the request XMLHTTP. send ();} function statechange () {// judge whether the asynchronous call has been completed if (XMLHTTP. readystate = 4) {// check whether the code is OK when the code is completed. If (XMLHTTP. status = 200) {// pass the returned data to the filling method filldata (XMLHTTP. responsetext) ;}} function filldata (strcity) {document. getelementbyidx ("dropdownlist1 "). options. length = 0; var indexofcity; var city; // cut the passed string while (strcity. length> 0) {// determines whether the last string is indexofcity = STRC Ity. indexof (","); If (indexofcity> 0) {city = strcity. substring (0, indexofcity); strcity = strcity. substring (indexofcity + 1); // fill in the drop-down box document. getelementbyidx ("dropdownlist1 "). add (New Option (city, city);} else {// if the last string is lastcity = strcity. substring (0, 2); document. getelementbyidx ("dropdownlist1 "). add (New Option (lastcity, lastcity); break ;};}</SCRIPT> protected void page_load (Object sender, Eventargs e) {// obtain the passed parameter string city = request. querystring ["city"]; response. clear (); // determine the city name switch (city) {Case "Beijing": // fill in the relevant region response. write ("Chaoyang, Haidian, Dongcheng, Xicheng"); break; Case "Shanghai": response. write ("Pudong, Jingan, Hongkou, Xuhui"); break; Case "Jinan": response. write ("historical, historical, city, flyover"); break ;}}use callback technology to achieve local refresh <SCRIPT type = "text/Jav Ascript "> function filldata () {var city = document. getelementbyidx ("textbox1 "). value; <% = This. clientscript. getcallbackeventreference (this, "city", "filldll", null) % >;} function filldll (strcity) {document. getelementbyidx ("dropdownlist1 "). options. length = 0; var indexofcity; var city; // cut the passed string while (strcity. length> 0) {// determines whether the last string is indexofcity = strcity. indexof (","); If (indexofcity> 0) {city = strci Ty. substring (0, indexofcity); strcity = strcity. substring (indexofcity + 1); // fill in the drop-down box document. getelementbyidx ("dropdownlist1 "). add (New Option (city, city);} else {// if it is the last string document. getelementbyidx ("dropdownlist1 "). add (New Option (strcity, strcity); break ;};}</SCRIPT> private string _ data; Public String getcallbackresult () {// return the processed data return _ data;} public void raisecallbackevent (string event Argument) {// determine the passed parameter switch (eventargument) {Case "Beijing": _ DATA = "Chaoyang, Haidian, Dongcheng, Xicheng"; break; Case "Shanghai ": _ DATA = "Pudong, Jingan, Xuhui, Hongkou"; break; Case "Jinan": _ DATA = "licheng, Lichuan, city center, Tianqiao"; break ;}} ------------------------------------------------------------------------------------- IFRAME implements partial refresh <script language = "JavaScript"> function search () {var city = document. getelementbyidx ("textbox1 "). value; If (City! = "") {Document. getelementbyidx ("iframe1"). src = "myframe. aspx? City = "+ city ;}</SCRIPT> <IFRAME src =" myframe. aspx "style =" text-align: center "id =" iframe1 "width =" 100% "Height =" 100% "frameborder =" 0 "scrolling =" no "/> second page myframe. aspx <Div style = "text-align: Center"> <asp: dropdownlist id = "dropdownlist1" runat = "server" width = "154px"> </ASP: dropdownlist> </div> protected void page_load (Object sender, eventargs e) {// obtain the passed parameter string city = request. querystring ["Ci Ty "]; // determine the city name switch (city) {Case" Beijing ": // fill in the relevant area dropdownlist1.items. clear (); dropdownlist1.items. add ("Chaoyang"); dropdownlist1.items. add ("Haidian"); dropdownlist1.items. add ("Dongcheng"); dropdownlist1.items. add ("Xicheng"); break; Case "Shanghai": dropdownlist1.items. clear (); dropdownlist1.items. add ("Pudong"); dropdownlist1.items. add ("Jingan"); dropdownlist1.items. add ("Hongkou"); dropdownlist1.items. add ("Xuhui"); break; Case "Jinan": dropdow Nlist1.items. clear (); dropdownlist1.items. add ("historical"); dropdownlist1.items. add ("licheng"); dropdownlist1.items. add ("city center"); dropdownlist1.items. add ("Tianqiao"); break; }}using the script method to perform local refresh <SCRIPT type = "text/JavaScript"> function filldata (strcity) {document. getelementbyidx ("dropdownlist1 "). options. length = 0; var indexofcity; var city ;// Cut the passed string while (strcity. length> 0) {// determines whether the last string is indexofcity = strcity. indexof (","); If (indexofcity> 0) {city = strcity. substring (0, indexofcity); strcity = strcity. substring (indexofcity + 1); // fill in the drop-down box document. getelementbyidx ("dropdownlist1 "). add (New Option (city, city);} else {// if it is the last string document. getelementbyidx ("dropdownlist1 "). add (New Option (strcity, strcity); break ;};}</SCRIPT> using System. Text; protected void page_load (Object sender, eventargs e) {// create a string connection object stringbuilder myscript = new stringbuilder (); // use a string to organize a Javascript script method myscript. append ("function seekcity () {\ n"); myscript. append ("Var city = document. getelementbyidx ('textbox1 '). value; \ n "); myscript. append ("Switch (city) {\ n"); myscript. append ("case 'beijing': \ n"); myscript. append ("filldata ('" + getcitystr ("Beijing") + "'); \ n"); mysc Ript. append ("break; \ n"); myscript. append ("case 'shanghai': \ n"); myscript. append ("filldata ('" + getcitystr ("Shanghai") + "'); \ n"); myscript. append ("break; \ n"); myscript. append ("case 'jinan ': \ n"); myscript. append ("filldata ('" + getcitystr ("Jinan") + "'); \ n"); myscript. append ("break;} \ n"); myscript. append ("} \ n"); // use the register script method to register the script method written in this string on the client side of the page. Page. clientscript. registerclientscriptblock (typeof (string), "seekcity", myscript. tostring (), true);} // obtain the city name and return the city's district/county string private string getcitystr (string incity) {string city = ""; Switch (incity) {Case "Beijing": City = "Chaoyang, Haidian, Dongcheng, Xicheng"; break; Case "Shanghai": City = "Pudong, Jingan, Xuhui, Hongkou"; break; case "Jinan": City = "licheng, historical city, city, flyover"; break;} // return the string containing the district/county connection return city ;}

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.