简体   繁体   中英

file is not defined in Javascript when reading local file

<html>
<head>
<title>My first styled page</title>
</head> 
<body>

<script> 
var reader = new FileReader();
reader.onload = function(){
var text = reader.result;
document.querySelector('body').append(text);
};
reader.readAsText(README, "us-ascii");
</script>

<!-- Site navigation menu -->
<ul class="navbar">
<li><a href="alamode-fetch">Alamode</a>
<li><a href="README">Readme</a>
<li><a href="town.html">My town</a>
<li><a href="links.html">Links</a>
</ul>

<!-- Main content -->
<h1>My first styled page</h1>
<p>Welcome to my styled page!
<p>It lacks images, but at least it has style.And it has links, even if they       don't go anywhere&hellip;
<p>There should be more here, but I don't know what yet.
<!-- Sign and date the page, it's only polite! -->
<address>Made 5 April 2004<br> 
by myself.
</address>
</body>
</html>

Above is my html file. I was trying to reading the local file named as README. When I execute my html file, looks like there is nothing happened with my javascript. And I found that in the firefox, it reminds that README is not defined. I have stuck on it for whole day....

The problem is README . Javascript expect README will be a variable but you don't define it.

Check out https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsText

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