download XSLX or DOCX file using XMLHTTPRequest response in IE 9
<p>How can i download XSLX or DOCX file using XMLHTTPRequest response in IE 9 ? I only need the IE 9 Solution.</p>

<p>This code works good for plain-text and csv Files but when i try to download XSLX or DOCX files nothing happens.</p>

<p>The response came from a java servlet with response-content-type set to</p>

<pre><code>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
</code></pre>

<p>The javascript function that i need for downloading files.</p>

<pre><code>function submitForm(command, event) {
            disableButtons();
            var form = $('form[name=myForm]');
            var dataString = form.serialize();
            var xhr = new XMLHttpRequest();
            xhr.open('POST', myURL, true);
            //tested =&gt; xhr.responseType = 'arraybuffer';
            //tested =&gt; try { xhr.responseType = "arraybuffer"; } catch (e) { }; application/zip
            //tested =&gt; try { xhr.responseType = "msxml-document"; } catch (e) { };

            xhr.onreadystatechange = function() {

                if(xhr.readyState == 4){
                    // xhr is complete (200 for web servers, 0 for local files in IE)
                    if ((xhr.status == 200)||(xhr.status == 0)){
                        // good

                        var filename = "";
                        var disposition = xhr.getResponseHeader('Content-Disposition');
                        if (disposition &amp;&amp; disposition.indexOf('attachment') !== -1) {
                            var filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
                            var matches = filenameRegex.exec(disposition);
                            if (matches != null &amp;&amp; matches[1]) filename = matches[1].replace(/['"]/g, '');
                        }
                        var type = xhr.getResponseHeader('Content-Type');
                        var URL = window.URL || window.webkitURL;
                        var downloadUrl = URL.createObjectURL(blob);

                        var frame = document.createElement('iframe');
                        document.body.appendChild(frame);

                        frame.contentWindow.document.open(type, "replace");
                        frame.contentWindow.document.write(xhr.responseText); //tried also responseXML
                        frame.contentWindow.document.close();
                        frame.contentWindow.focus();
                        frame.contentWindow.document.execCommand('SaveAs', true, filename);

                        document.body.removeChild(frame);

                        setTimeout(function () {
                            URL.revokeObjectURL(downloadUrl);
                        }, 100); // cleanup
                    } else{
                        // error
                    }
                }
            }
            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            xhr.send(dataString);
        }
</code></pre>