AJAX traversal of XML document methods _ajax related

Source: Internet
Author: User

The example in this article describes how Ajax traverses an XML document. Share to everyone for your reference. The specific analysis is as follows:

The XMLHttpRequest object provides two properties that can be used to access the server response. The first property ResponseText provides the response as a string, and the second property Responsexml provides the response as an XML object. Some simple use cases are good for getting a response in simple text, such as displaying a response in a warning box, or responding to a word that only indicates success or failure.
The example in front of <ajax summary > is to get the server response from the XMLHttpRequest object and to get the response as text using the ResponseText property of the XMLHttpRequest object.
This time we're going to use the Responsexml property of the XMLHttpRequest object to get the result as an XML document. This way, we can traverse the XML document using the method of the consortium DOM. (the previous article more or less talked about DOM, do not repeat here)

OK, let's look at the example below.

First and foremost, the XML document code (PARSEXML.XML) is as follows:

Parsexml.xml is as follows:

<?xml version= "1.0" encoding= "UTF-8"?>
<states>
<north>
<state>Minnesota< /state>
<state>Iowa</state>
<state>north dakota</state>
</north>
<south>
<state>Texas</state>
<state>Oklahoma</state>
<state >Louisiana</state>
</south>
<east>
<state>new york</state>
<state>north carolina</state>
<state>Massachusetts</state>
</east >
<west>
<state>California</state>
<state>Oregon</state>
<state>Nevada</state>
</west>
</states>

Myjsp.jsp is as follows:

<%@ page language= "java" import= "java.util.*" pageencoding= "Utf-8"%> <% String Path = Request.getcontextpath ()
;
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/"; %> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >  

I hope this article will help you with your AJAX programming.

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.