3

I couldn't find an answer to this problem I've been having.

function UploadBar() {
    this.reader = new FileReader();
    this.reader.addEventListener(
        "onloadstart"
        , function(evt) {alert("Hello World");}
        , false
    );
}

when I try to run this code it gives me an undefined_method_error in the javascript debugger in chrome. Could anyone be so kind as to tell me what is wrong here?

ovangle
  • 1,991
  • 1
  • 15
  • 29

1 Answers1

4

reader is not an element, so don't use .addEventListener Instead do the following.

function UploadBar() {
    this.reader = new FileReader();
    this.reader.onloadstart = function(e) { alert('Hello World') };  
}
aziz punjani
  • 25,586
  • 9
  • 47
  • 56
  • Note: As FileReader inherits from EventTarget, all those events can also be listened for by using the addEventListener method. source: https://developer.mozilla.org/en-US/docs/Web/API/FileReader. Although for some reason this method is not available in older Android browsers. – PhilT Apr 21 '15 at 21:09