captbrogers
captbrogers

Reputation: 494

Plain JS Ajax Upload Progress Event Not Working

I am trying to use object-oriented code to handle an AJAX upload. When I run the code, it sees the file, creates the XMLHttpRequest object, but I cannot seem to get the progress event to fire. The full source of my code can be found here: http://pastebin.com/89QawbS6

Here is a snippet:

var xhr = new XMLHttpRequest();

xhr.upload.addEventListener("progress", MyObj.trackProgress, false);

xhr.open("POST", url, true);
...

Then in that same object, different method:

trackProgress: function (event) {
    console.log(event);

    // stuff that should calculate percent
}

But that console.log(event) never fires.

Please note: I know jQuery is great, and there are a dozen awesome upload plugins that I could just use instead. I am not doing this for a class or homework, I just want to understand the process better myself. So offering a jQuery plugin as an answer is not what I'm looking for. I'm trying to make myself less dependent on jQuery.

Upvotes: 0

Views: 670

Answers (1)

peterfoldi
peterfoldi

Reputation: 7471

This FF bug might be the reason for your issue. It's reported on MacOSX and another similar bug on Linux. I don't know if that matters but I tested on Windows. I still believe that your code is fine.

Upvotes: 1

Related Questions