Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there AJAX progress event in IE and how to use it?

I tried all I could think of to at least get to the progress function in IE9 but nothing works. All other browsers get inside of the progress function and write test text without any problems. Hopefully someone can help me. Thank you!

     var info = document.getElementById('info');
     var xhr;
        if (window.XMLHttpRequest) {
            xhr = new XMLHttpRequest();  
        } 
        else if (window.ActiveXObject) { 
            try {  
                xhr = new ActiveXObject("Msxml2.XMLHTTP");  
            } 
            catch (e) {  
                try {  
                    xhr = new ActiveXObject("Microsoft.XMLHTTP");  
                } 
                catch (e) {}  
            }  
        }
        xhr.attachEvent("onprogress", function(e) {
            info.innerHTML += "loading...<br />";   
        });

        /*xhr.addEventListener("progress", function(e) {
            info.innerHTML += "loading...<br />";   
        }, false);*/

        xhr.open("GET", "10_MB_File.txt", true);
        xhr.send(null);
like image 867
user1154269 Avatar asked Oct 12 '12 20:10

user1154269


2 Answers

The onprogress event is part of the XMLHttpRequest Level 2 spec...

  • http://www.w3.org/TR/XMLHttpRequest2/

  • http://www.w3.org/TR/XMLHttpRequest2/#event-handlers

... which is not supported by IE 9 and below. However, IE 10 is supposed to support it...

  • http://msdn.microsoft.com/en-us/library/ie/hh673569(v=vs.85).aspx#Enhanced_Event_Support

For more information on which browsers support XHR Level 2, take a look at caniuse.com...

  • http://caniuse.com/#feat=xhr2
like image 193
Hristo Avatar answered Oct 15 '22 10:10

Hristo


IE9 and under do not support onprogress, hence why you can not get it to work.

var xhr = new XMLHttpRequest();
console.log('onprogress' in xhr);
like image 22
epascarello Avatar answered Oct 15 '22 10:10

epascarello