简体   繁体   中英

Read file from HTML

I am trying to read a text file from my computer to a website. I have it working in IE, but I can't seem to make it work in Chrome. I'm not skilled in html really at all, so any assistance would be great!

<html>
<body>

    <div id = "content">
    </div>

    <script lang = "javascript">

    if (window.XMLHttpRequest)
    {
        xhttp=new XMLHttpRequest();
    }
    else // Internet Explorer 5/6
    { 
        xhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xhttp.open("GET","./Test.txt",false);
    xhttp.send("");
    xmlDoc=xhttp.responseText;

    document.getElementById('content').innerHTML = xmlDoc;
    </script>

</body>
</html> 

使用此处的Javascript File API 示例进行操作

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM