前端下载接收后端传的文件流



$.ajax({
        url: "/test4",
        async:true,
        contentType:'application/x-www-form-urlencoded',
        data:{},
        xhr:function(){
            var xhr = new XMLHttpRequest();
            xhr.responseType = 'arraybuffer';
            return xhr;
        },
        type:'POST',
        timeout:60000,
        success: function (result) {
            var blob = new Blob([result],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;chatset=utf-8"})
            Temp = document.createElement("a");
            Temp.href = window.URL.createObjectURL(blob);
            Temp.download = new Date().getTime()+'excel';
            $('body').append(Temp)
            Temp.click();
        }
    });
原文地址:https://www.cnblogs.com/Crush123/p/14143850.html