level 1
专专业牛皮癣
楼主
编译的是报跨域的错,应该怎样才能读取到xml文件里的PC549,麻烦大佬指点

index.xml文件内容:
<?xml version="1.0" encoding="utf-8"?>
<root>
<WriteTime>2016-10-09 14:37:43</WriteTime>
<Status>1</Status>
<log>
</log>
<ComputeName>PC549</ComputeName>
</root>
JS我是这样写的
<body>
<input id="test" type="button" value="按钮">
</body>
<script>
$("#test").click(function () {
var xmldoc = loadXmlFile("./index.xml");
var elements = xmldoc.getElementsByTagName("ComputeName");
alert(elements[0].firstChild.nodeValue);
});
function loadXmlFile(xmlFile) {
var xmlDom = null;
if (window.ActiveXObject) {
xmlDom = new ActiveXObject("Microsoft.XMLDOM");
xmlDom.async = "false";
xmlDom.load(xmlFile);
console.log(1);
}
else if (document.implementation && document.implementation.createDocument) {
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET", xmlFile, false);
xmlhttp.send(null);
xmlDom = xmlhttp.responseXML;
console.log(2);
}
else {
xmlDom = null;
console.log(3);
}
return xmlDom;
};
</script>
2021年08月10日 04点08分
1

index.xml文件内容:<?xml version="1.0" encoding="utf-8"?>
<root>
<WriteTime>2016-10-09 14:37:43</WriteTime>
<Status>1</Status>
<log>
</log>
<ComputeName>PC549</ComputeName>
</root>
JS我是这样写的
<body>
<input id="test" type="button" value="按钮">
</body>
<script>
$("#test").click(function () {
var xmldoc = loadXmlFile("./index.xml");
var elements = xmldoc.getElementsByTagName("ComputeName");
alert(elements[0].firstChild.nodeValue);
});
function loadXmlFile(xmlFile) {
var xmlDom = null;
if (window.ActiveXObject) {
xmlDom = new ActiveXObject("Microsoft.XMLDOM");
xmlDom.async = "false";
xmlDom.load(xmlFile);
console.log(1);
}
else if (document.implementation && document.implementation.createDocument) {
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET", xmlFile, false);
xmlhttp.send(null);
xmlDom = xmlhttp.responseXML;
console.log(2);
}
else {
xmlDom = null;
console.log(3);
}
return xmlDom;
};
</script>