XMLHttpRequest upload progress event doesn't work in Firefox 10.0.2

て烟熏妆下的殇ゞ 提交于 2019-12-11 03:08:41

问题


I'm trying to create an ajax based upload form with progress bar. This is my code (the upload part of it):

$xhr = new XMLHttpRequest();
            $xhr.upload.addEventListener("progress",
                function(e) {
                    if (e.lengthComputable) {
                        $progress = (e.loaded / e.total) * 100;
                        $('#file-progress').css('width', $progressWidth * (e.loaded / e.total));
                        $('#percentage').html($progress.toFixed(2) + '%');
                    } else {
                        alert('Y U NO WORK?');
                    }
                }
            , false); 


            $xhr.onreadystatechange = function(e){
                if($xhr.readyState == 4) {
                    //i'll add this later
                }
            };

            $xhr.open('POST', 'handler.php', true);
            var $data = new FormData();
            $data.append('file', $file.files[0]);
            $xhr.send($data);

Everything works in Chrome (the progress bar and file upload) but in Firefox works only file upload without the progress bar. No errors, nothing. Firefox ignores the progress listener and i can't get why because as i have read Firefox should support XMLHttpRequest level 2.

来源:https://stackoverflow.com/questions/9550940/xmlhttprequest-upload-progress-event-doesnt-work-in-firefox-10-0-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!