AJAX 请求 XML 格式的数据


<script>

var xhr = new XMLHttpRequest();
xhr.open('GET', 'xml.php');
xhr.send();
xhr.onreadystatechange = function () {
if (this.readyState !== 4) return;
// this.responseXML 专门用于获取服务端返回的 XML 数据,操作方式就是通过 DOM 的方式操作
// 但是需要服务端响应头中的 Content-Type 必须是 application/xml
console.log(this.responseXML.documentElement.children[0].innerHTML);
console.log(this.responseXML.documentElement.getElementsByTagName('name')[0])
}

</script>
posted @ 2019-01-19 11:55  lujieting0  阅读(1089)  评论(0编辑  收藏  举报