0

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.

8
  • Progress event fires for me using your code. What browser are you testing this in? Progress event is not supported by all versions. See: developer.mozilla.org/en-US/docs/Web/API/… Commented Nov 4, 2013 at 19:09
  • @peterfoldi: Firefox 25. Commented Nov 4, 2013 at 19:16
  • Doesn't work in FF indeed. Works in Chrome. Commented Nov 4, 2013 at 19:21
  • Works. Try to upload big files. I don't know what's the min limit. I tested with a 900kbfile and it fired once, probably would fire more times if not running on localhost. But MDN says it's fired "zero or more times". So zero times fire is still ok and probably FF does that when the file is small. Commented Nov 4, 2013 at 19:30
  • 1
    This FF bug might be related: bugzilla.mozilla.org/show_bug.cgi?id=908375 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. Commented Nov 5, 2013 at 14:36

1 Answer 1

1
+50

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.