Функция этого апплета в основном для извлечения провинциальной, муниципальной и районной информации из базы данных и отображения ее в раскрывающемся списке с использованием асинхронного запроса:
Код заключается в следующем:
Код в базе данных и некоторую информацию о файле конфигурации опущены, в основном код в JavaScript:
$ (document) .ready (function () {$. get ("getProvince.do", function (result) {$ ("#showp"). html (result);});}) var xmlhttp; function mysend (str) {$ (document) .Read (function () {$ ("#show2"). document.getElementByIdx_x_x_x_x_x_x_x_x_x_x_x_x_x_x ("show"); show.innerhtml = ""; var province = document.getElementByIdx_x_x_x_x_x_x_x_x_x_x_x ("провинция"). ActiveXobject ("microsoft.xmlhttp");} xmlhttp.onreadystateChange = function () {if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {show.innerhtml = xmlhttp.ressetxtext; Encodeuricomponent (str); xmlhttp.open ("get", "getCity.do?provinceid="+ss, true); xmlhttp.send(nul Xmlhttprequest ();} else {xmlhttp = new activexobject ("microsoft.xmlhttp");} xmlhttp.onreadystatechange = function () {if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {vare2 == 4 && xmlhttp.status == 200) {vare2 == 4 & document.getElementByIdx_x_x_x_x_x_x_x_x_x_x_x ("show2"); show2.innerhtml = xmlhttp.responsetext;}} var ss = Encodeuricomponent (str); xmlhttp.open ("get", "getarea.do?cityId="+ss, true); xmlhttp.send(null);} Код на странице HTML:
расположение
Код в действии:
Package mobi.zhangsheng.jiejia.action; import java.io.ioexception; импорт java.io.printwriter; import java.util.list; импорт javax.annotation.resource; импорт javax.servlet.http.httpserveltrequest; import -javax.servlece.http.httpsesperserquest; org.apache.struts2.servletactuctionContext; Import org.springframework.stereotype.controller; import mobi.zhangsheng.jiejia.domain.areas; import mobi.zhangsheng.jiejia.service.agentsservice; импорт. Provinceaction {private int provinceid; private int cityId; @ResourcePrivate acties Shipers as; @ResourcePrivate AgentsService Ags; public int getProvinceId () {return provinceid;} public void setProvinceid (int provinceid) {this.provinceid = provinceid; void setCityId (int cityId) {this.cityId = cityId;} public void getProvince () {list provinceList = as.getAreasPrvincelist (); httpservletresponse rest = servletactionContext.getResponse (); ServletActionContext.getRequest (); // resp.SetContentType ("xml"); resp.setContentType ("text/html"); resp.setcharacterencoding ("utf-8"); попробуйте {printwriter out = resp.getwriter (); (IoException e) {e.printstacktrace ();}} public void getCity () {list citylist = as.getareascitylist (provinceid); httpservletresponse resp = ServletActionContext.getResponse (); // resp.SetContentType ("xml"); resp.setContentType ("text/html"); resp.setcharacterencoding ("utf-8"); попробуйте {printwriter out = resp.getwriter (); (IoException e) {e.printstacktrace ();}} public void getarea () {list arealist = as.getareascitylist (cityid); if (arealist.size () == 0) {} els ServletActionContext.getResponse (); resp.SetContentType ("text/html"); resp.setcharacterencoding ("utf-8"); try {printwriter out = resp.getwriter (); out.print ("");} catch (ioException e) {e.printStacktrace ();}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}};Основные коды функций все на нем. Если вы не понимаете, пожалуйста, свяжитесь с QQ: 1037139984. Я желаю вам всего хорошего развития, учиться вместе и расти вместе.