Extjs Ajax parses XML data

Source: Internet
Author: User

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;}

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.