普通的jQuery中的ajax请求后台,并不能处理Blob类型的数据,这里用的原生的XMLHttpRequest请求后台

     var xhr = new XMLHttpRequest();
            xhr.open("get",url, true);
            xhr.responseType = "blob";
            xhr.onload = function() {

                if (this.status == 200) {
                    $.unblockUI();
                    var blob = this.response;
                    if(blob.type == "text/html"){
                        return false
                    }
                    var fileName = "aaaa.xlsx";
                    if(window.navigator.msSaveOrOpenBlob){            // IE浏览器下
                        navigator.msSaveBlob(blob, fileName);
                    } else {
                        var  link = document.createElement("a");
                        link.href = window.URL.createObjectURL(blob);
                        link.download = fileName;
                        link.click();
                        window.URL.revokeObjectURL(link.href);
                    }
                }else{
                }
            }

更多推荐

ajax 下载文件 返回blob类型