I can’t figure out why neither readSuccess() or readFailure() are getting called in the following:
function readMyFile(){
var reader = new FileReader();
reader.onload = readSuccess;
reader.onerror = readFailure;
reader.readAsText("test.txt");
function readSuccess(evt){
alert(evt.target.result);
}
function readFailure(evt) {
alert("Did not read file!");
}
}
When I step though the code in the Chrome javascript debugger, it steps past the reader.readAsText("test.text"); command, but then exits the whole function, never calling readSuccess() or readFailure()
You can’t specify a file with a string in
reader.readAsText(), it needs to be a reference to aBlob: see the documentation.You should be getting the
Blobfrom a file-type input field, check out these awesome examples.