Search code examples
javascriptxmlhttprequest

XMLHttpRequest not working for IE 11 for file download


var formdata = new FormData();

    var xhr = null;
    if(typeof XMLHttpRequest != "undefined"){

        xhr = new XMLHttpRequest();
    }
    else if(typeof window.ActiveXObject != "undefined"){
        try {

            xhr = new ActiveXObject("Msxml2.XMLHTTP.4.0");
        }
        catch(e){
            try {

                xhr = new ActiveXObject("MSXML2.XMLHTTP");
            }
            catch(e){
                try {

                    xhr = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(e){

                    xhr = null;
                }
            }
        }
    }

    xhr.open("GET",url, true); ///fileUploadTester/FileUploader

    xhr.send(formdata);


    xhr.responseType = "arraybuffer";
    xhr.onload = function(e) {


        var ua = window.navigator.userAgent;
        var msie = ua.indexOf("MSIE ");

        if (msie > 0) // If Internet Explorer, return version number
        {

            var urlIE = URL;
            window.location = urlIE;
        }
        else
        {
            window.location = this.responseURL;
        }
    };
}

The above code is from my javaScript method when i call that method my requirement is to download file for user. In java i have a method to generate file and add it to response

For other browsers i am able to call the method and get response back but for IE 11 i am not able to do. Any Solution for this or any errors in my code?


Solution

  • Got the Answer The way i was getting browser name was wrong. Once i got correct browser name using javascript it stated working