[英]Flot graph not working in Firefox or Internet Explorer, only Chrome
[英]Why is this working in fireFox but not in Chrome or Internet Explorer 9?
我有一个xml文件和一个引用它的文件。 在Firefox中,我得到了期望的响应,但在安装的其他两个浏览器(Chrome和IE9)中却没有得到响应。 谁能告诉我我做错了吗? HTML:
<!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(shredder-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
您在脚本中有一个XHR调用。 Chrome默认不会通过XHR从本地文件系统加载文件。 如果通过file://协议查看示例,则会影响资源的加载。 要启用此类文件的加载,应使用--allow-file-access-from-files标志。
IE也有一些限制,尽管在某些情况下可以使本地访问的XHR调用起作用。
或者,从Web服务器而不是本地文件系统提供服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.