0
我有一个xml文件和一个引用它的文件。在Firefox中,我收到了我期待的响应,但未安装其他两种浏览器(Chrome & IE9)。 任何人都可以告诉我我做错了吗? HTML:为什么这个工作在fireFox中,但不是在Chrome或Internet Explorer 9中?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test File List Document</title>
</head>
<body>
<div>Output</div>
<div id="testDiv"></div>
</body>
<script>
//XML request
var xmlhttp, xmlDoc;
// code for IE6, IE5
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
};
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "shredder-data.xml", false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
//test
document.getElementById("testDiv").innerHTML=xmlDoc.getElementsByTagName("crc")[0].childNodes[0].nodeValue;
</script>
</html>
XML(切碎机 - data.html}
<?xml version="1.0" encoding="utf-8"?>
<shredders>
<personal>
<model name="P-20">
<headline>Fellowes PowerShred P-20 Strip-Cut Personal Shredder</headline>
<users>1</users>
<crc>3401401</crc>
<cut>Strip</cut>
<jam>no</jam>
<sheet_capacity>5</sheet_capacity>
<run_time>2/25</run_time>
<bin_capacity>11</bin_capacity>
<staples>no</staples>
<paperclips>no</paperclips>
<credit-cards>no</credit-cards>
<CDs>no</CDs>
</model>
<model name="P-35c">
<headline>Fellowes Powershred P-35C Cross-Cut Personal Shredder with Safety Lock</headline>
<users>1</users>
<crc>3008801</crc>
<cut>Strip</cut>
<jam>no</jam>
<sheet_capacity>2-4/15</sheet_capacity>
<run_time>2/25</run_time>
<bin_capacity>4.5</bin_capacity>
<staples>yes</staples>
<paperclips>no</paperclips>
<credit-cards>yes</credit-cards>
<CDs>no</CDs>
</model>
</personal>
</shredders>
我希望的输出将是:
Output
3401401
为什么你认为OP在'file://协议下?在Firefox中工作。如果这个问题是你说的,在Firefox中不应该工作,但工作。 –