js 获取xml内容

var orderDoc;
//获取xml文件
function loadXmlFile(xmlFile) {
	var xmlDom = null;
	if (window.ActiveXObject) {
		xmlDom = new ActiveXObject("Microsoft.XMLDOM");
		xmlDom.async = false;
		xmlDom.load(xmlFile) || xmlDom.loadXML(xmlFile); //如果用的是XML字符串//如果用的是xml文件
	} else if (document.implementation && document.implementation.createDocument) {
		var xmlhttp = new window.XMLHttpRequest();
		xmlhttp.open("GET", xmlFile, false);
		xmlhttp.send(null);
		xmlDom = xmlhttp.responseXML;
	} else {
		xmlDom = null;
	}
	return xmlDom;
}
 
//获得页面内容
function getContent() {
	orderDoc = loadXmlFile("./js/cdcatalog.xml");
	console.log(orderDoc)
}

getContent();

posted @ 2020-08-03 18:25  清梦徐徐丶莫  阅读(954)  评论(0编辑  收藏  举报