I haven't used JavaScript in a while and I can't seem to read a text file and display the contents.
I've tried onload
as well as onloadend
. If I just put reader.onload = alert('Hello');
the alert fires, but I can't get anything to work with the function.
Not exactly sure where to go from here. I've tried defining the function after reader.onload = function(evt)...
but that doesn't work.
I've tried in Safari 6.0.5 and Chrome as well.
<!DOCTYPE HTML>
<html>
<head>
<title>Pi to Colors</title>
</head>
<body>
<script>
function readFile() {
var reader = new FileReader();
reader.onload = readSuccess;
function readSuccess(evt) {
var field = document.getElementById('main');
field.innerHTML = evt.target.result;
};
reader.readAsText("/pi.txt");
}
</script>
<div id="main">
</div>
</body>
</html>