---
title: "解析 Ajax 的 response.responseXML"
author: "编程足球"
date: "2012-02-20T17:26:59Z"
tags: []
categories: ["Web前端"]
slug: "ajax-response-responsexml"
draft: false
lastmod: "2012-02-20T17:26:43Z"
id: 1413831
url: "https://lingf.iteye.com/blog/1413831"
---

在Ajax时候,服务器一般是返回json数据,然后进行解析.但是有时候却是放回xml.
eg:

```xml

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
	xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<soap:Body>
		<insertCustomQueryReportResponse 
			xmlns="http://services.openreports.efs.org">
			<out>
				<message xmlns="http://output.services.openreports.efs.org">
					报表系统没有该系统的报表模板，请联系管理员。
				</message>
				<success xmlns="http://output.services.openreports.efs.org">
					fail
				</success>
			</out>
		</insertCustomQueryReportResponse>
	</soap:Body>
</soap:Envelope>

```


现在要获得Message的值，则可以通过

```js

// 在FF调试的时候会发现tag 为underfind 奇怪
success : function(response, options) {
		var xmlDoc = response.responseXML;
		var tag = xmlDoc.getElementsByTagName("message");
		//alert(tag[0].textContent); //FF
		alert(tag[0].text); //IE
	},

```