ITeye博客

解析 Ajax 的 response.responseXML

编程足球 · 2012-02-20 17:26 · JavaScript · Web前端 · Markdown

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


<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的值,则可以通过


// 在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
	},

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。