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.