Extjs Ajax retrieves XML data from the background and displays it on the page
Page JS
Function getallareainfos () {var areaname = ""; Ext. ajax. request ({method: 'post', URL: 'allareainfos ', Params: {"areaname": areaname}, waitmsg: 'Data is being updated. Please wait... ', success: function (response, options) {var xmldoc = response. responsexml; If (xmldoc! = NULL) {var AIS = xmldoc. getelementsbytagname ("areainfo"); If (AIS! = NULL & AIS. length> 0) {for (VAR I = 0; I <AIS. length; I ++) // dB {var asid = (AIS [I]. getelementsbytagname ("ID") [0]. childnodes [0]. nodevalue); // ID var asname = (AIS [I]. getelementsbytagname ("name") [0]. childnodes [0]. nodevalue); // The name of the I-th areainfos var allcapacity = (AIS [I]. getelementsbytagname ("allcapacity") [0]. childnodes [0]. nodevalue); // The total installation capacity of the I-th areainfos // document. getelementbyid (asname ). in Nerhtml = ""; document. getelementbyid (asname ). innerhtml = allcapacity; // displayed on the page }}}, failure: function (response, options) {Ext. MSG. alert ("message prompt", "An error occurred while retrieving database data. Please try again later! ") ;}, Autoabort: false });}
Action
public String getAllAreaInfos() {try {List<Areainfo> list = null;if(areaName!=null&&!areaName.equalsIgnoreCase("null")&&areaName.trim().length()>0){list = mapInfos.findAllAreaInfos(this.subStringAreaName(areaName));}elselist = mapInfos.findAllAreaInfos(null);response.setContentType("text/xml;charset=utf-8");response.setCharacterEncoding("utf-8");PrintWriter pw = null;pw = response.getWriter();StringBuffer sb = new StringBuffer();sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");sb.append("<Items>");if(list==null){sb.append("<Areainfo>");sb.append("<id>").append("no").append("</id>");sb.append("</Areainfo>");}else{for (int i = 0; i < list.size(); i++) {Areainfo v = list.get(i);sb.append("<Areainfo>");sb.append("<id>").append(v.getId()).append("</id>");sb.append("<name>").append(v.getName()).append("</name>");sb.append("<allCapacity>").append(v.getAllcapacity()).append("</allCapacity>");sb.append("</Areainfo>");}}sb.append("</Items>");String xmlDBTree = sb.toString();pw.print(xmlDBTree);pw.flush();pw.close();} catch (Exception e) {e.printStackTrace();}return null;}