function loadXmlFile(xmlFile)//xmlFile 是xml文件的地址
{
var xmlDom = null;
if (window.ActiveXObject)//IE浏览器中读取xml文件
{
xmlDom = new ActiveXObject("Microsoft.XMLDOM ");
xmlDom.async="false ";
xmlDom.load(xmlFile);
}
else if(document.implementation && document.implementation.createDocument)
{
//.Firefox,Chrome 浏览器中读取xml文件 ,Chrome 需要开服务器才能访问
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET", xmlFile, false);
xmlhttp.send(null);
xmlDom = xmlhttp.responseXML;
}
else
{
xmlDom = null;
}
return xmlDom;
};
var aaa=loadXmlFile("story/story1.xml");
console.log(aaa);
试过三种JS的方法,都失败了,期间不知道什么原因,以上代码成功过。走的应该是CHROME浏览器的路线。
后来不知道什么原因,又失败了。
if(document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.async = false;
xmlDoc.load(xmlFile);
}
使用这种方法,xmlDoc.load()方法找不到,不知道为什么。
1 个回复
badfl - mui详细文档:http://ask.dcloud.net.cn/article/1039
可以使用MUI封装好的Ajax方法来获取XML
http://dev.dcloud.net.cn/mui/ajax/