Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么这在fireFox中有效,而在Chrome或InternetExplorer9中无效?_Javascript_Html_Google Chrome_Internet Explorer_Firefox - Fatal编程技术网

Javascript 为什么这在fireFox中有效,而在Chrome或InternetExplorer9中无效?

Javascript 为什么这在fireFox中有效,而在Chrome或InternetExplorer9中无效?,javascript,html,google-chrome,internet-explorer,firefox,Javascript,Html,Google Chrome,Internet Explorer,Firefox,我有一个xml文件和一个引用它的文件。在Firefox中,我得到了我期望的响应,但在另外两个安装了Chrome和IE9的浏览器中却没有。 谁能告诉我我做错了什么吗? HTML: 脚本中有一个XHR调用。默认情况下,Chrome不会通过XHR从本地文件系统加载文件。如果通过file://协议查看示例,则会影响资源的加载。要启用此类文件的加载,应使用标志-允许从文件访问文件 IE也有一些限制,尽管在某些条件下可以进行本地访问的XHR调用 或者,从web服务器而不是本地文件系统提供此服务。为什么您认为

我有一个xml文件和一个引用它的文件。在Firefox中,我得到了我期望的响应,但在另外两个安装了Chrome和IE9的浏览器中却没有。 谁能告诉我我做错了什么吗? HTML:


脚本中有一个XHR调用。默认情况下,Chrome不会通过XHR从本地文件系统加载文件。如果通过file://协议查看示例,则会影响资源的加载。要启用此类文件的加载,应使用标志-允许从文件访问文件

IE也有一些限制,尽管在某些条件下可以进行本地访问的XHR调用

或者,从web服务器而不是本地文件系统提供此服务。

为什么您认为OP在file://协议下?在firefox中,它正在工作。如果这个问题是你说的,在firefox中不应该工作,但可以工作。
<!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 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