Home  >  Article  >  Web Front-end  >  Ajax method to traverse xml document

Ajax method to traverse xml document

亚连
亚连Original
2018-05-25 10:34:591549browse

This article mainly introduces the method of ajax traversing XML documents. It analyzes the implementation techniques of jsp combined with Ajax traversing XML documents through examples. It has certain reference value. Friends who need it can refer to it.

The examples of this article are described Ajax method for traversing xml documents. Share it with everyone for your reference. The specific analysis is as follows:

The XMLHttpRequest object provides two attributes that can be used to access the server response. The first attribute, responseText, provides the response as a string, and the second attribute, responseXML, provides the response as an XML object. Some simple use cases are suitable for getting the response by simple text, such as displaying the response in an alert box, or the response is just a word indicating success or failure
The example in the previous f910214d61c74dcaf6573f7d2e3a0733 was obtained from the XMLHttpRequest object The server responds and gets the response as text using the responseText property of the XMLHttpRequest object.
This time we will use the responseXML attribute of the XMLHttpRequest object to obtain the result as an XML document. In this way, we can use the W3C DOM method to traverse the XML document. (The previous article has more or less talked about DOM, so I won’t repeat it here)

OK, let’s look at the example.

First of all, there is a piece of XML document code (parseXML.xml) as follows:

parseXML.xml is as follows:





Minnesota
Iowa
North Dakota


Texas
Oklahoma
Louisiana


New York
North Carolina
Massachusetts


California
Oregon
Nevada


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+"/";
%>




My JSP 'MyJsp.jsp' starting page


 






The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Ajax upload method to implement js processing based on server-side return data

Double-layer ajax embedding Set (can be multi-layered) usage examples

Ajax implementation of pop-up non-refresh city selection function code

The above is the detailed content of Ajax method to traverse xml document. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn