jquery.form.js 实现 ajax提交表单并监听请求完成实现下载期间显示遮罩层
作者:互联网
function doDownZipFile(){ var options = { url: $("#downZip").attr("action"), //url: "/xmTrade/maitian/plat/fileupload/downloadZipFile.action", //target: "#div2", type: "post", beforeSend:function(xhr){//请求之前 //console.info("打开遮罩层") $.blockUI({message: "<h1>打包下载可能比较耗时,请耐心等待.........</h1>"}); }, success: function (result) { let fileName = 'pic.zip'; const excelBlob = result.data if ('msSaveOrOpenBlob' in navigator) { // Microsoft Edge and Microsoft Internet Explorer 10-11 window.navigator.msSaveOrOpenBlob(excelBlob, fileName) } else{ const elink = document.createElement('a') // 创建a标签 elink.download = fileName elink.style.display = 'none' const blob = new Blob([excelBlob]) elink.href = URL.createObjectURL(blob) document.body.appendChild(elink) elink.click() document.body.removeChild(elink) } }, complete: function (xhr) {//请求完成 //console.info("关闭遮罩层") $.unblockUI(); } }; $("#downZip").ajaxSubmit(options); }
需要依赖:
jquery.form.js
<script type="text/javascript" charset="utf-8" src="<mt:basePath/>/common/js/maitian/jquery.form.js?v=0721"></script>
标签:jquery,遮罩,elink,form,function,js,const,fileName 来源: https://www.cnblogs.com/izyh/p/16023072.html