XHR progress only after firing

I'm trying to create a progress bar to download a file, but for some reason, the response to the XHR move only fires once, at the end. However, it works at 100% fine (it works when a file is downloaded) if I have a Firebug window open. I am testing this on localhost.

My code is very long, but here is the gist:

is_uploading = $.ajax({
                        url: "/includes/upload.php?a=" + a_id,
                        type: "POST",
                        data: formdata,
                        processData: false,
                        contentType: false,
                        dataType: "JSON",
                        xhr: function(){
                            var xhr = new window.XMLHttpRequest();
                            xhr.upload.addEventListener("progress",function(evt){
                                        alert('yay');//test to see if the event is firing...this should be alerting A LOT
                                        if (evt.lengthComputable){
                                                //do stuff
                                        }
                            },false);

                            return xhr;
                        }

                        ...more options here beforesend,success,etc

I have been pulling my hair over the past few hours, so any help would be appreciated. I don’t know why it works with firebug open console, but only works at the end if it is closed ...

+4
source share

All Articles