post 方式 传json参数 下载excel

   var params = getParams();
            params.action = 'auditListExport';

            var xhr = new XMLHttpRequest();
            xhr.responseType = "arraybuffer";
            xhr.open("POST", downloadUrl);

            xhr.onload=function(){
                const blob = new Blob([this.response], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
                
                if ('download' in document.createElement('a')) {
                    const link = document.createElement('a');
                 
                    link.download = '审核结果.csv';
                    link.style.display = 'none';
                    link.href = URL.createObjectURL(blob);
                    document.body.appendChild(link);
                    link.click();
                    URL.revokeObjectURL(link.href);
                    document.body.removeChild(link);
                } else {
                    navigator.msSaveBlob(blob);
                }
            }

            xhr.setRequestHeader('Content-type','application/json');
            xhr.send(JSON.stringify(params));
          
           
 

 

 
posted @ 2019-11-22 15:57  nini123123  阅读(698)  评论(0编辑  收藏  举报