1.XML格式概念:可扩展标记语言
2.XML格式数据
<?xml version="1.0" encoding="utf-8" ?> <users> <user> <name>刘备</name> <sex>男</sex> <age>160</age> <desc>桃园三结义</desc> </user> <user> <name>隔壁小王</name> <sex>猛男</sex> <age>18</age> <desc>年轻气力盛</desc> </user> </users>
3.在php文件中读取xml格式的文件
<?php header(‘content-type:text/xml;charset=utf-8‘); //content-type:text/xml;
$res = file_get_contents("01-data.xml"); echo $res;
?>
4.发送ajax请求,获取xml数据 xml格式数据需要使用.responseXML来进行接收,得到一个dom对象
var bt = document.getElementById(‘bt‘) bt.onclick = function () { var xhr =new XMLHttpRequest() xhr.open("get", "aa.php") xhr.send() xhr.onreadystatechange=function(){ if(xhr.readyState===4){ if(xhr.status===200){ console.log(xhr.responseXML) //xhr.responseXML
} } } }
原文:https://www.cnblogs.com/zhaodz/p/11629141.html