JavaScript~~ 发送&接收文件流
获取文件流
varurl="/map/download?_beanid="+_beanid+"&buttonid="+buttonid;varxhr=newXMLHttpRequest();xhr.open('GET',url,true);xhr.responseType="blob";xhr.onload=function(){if(this.status==200){//varblob=this.response;varblob=newBlob([this.response]);/*if(d.headers('content-disposition').indexOf('filename')!=-1){downloadTitle=d.headers('content-disposition').split(';')[1].split('=')[1];downloadTitle=decodeURI(downloadTitle);}待用*/if(typeofwindow.navigator.msSaveBlob!=='undefined'){window.navigator.msSaveBlob(blob,downloadTitle);}else{varobjectUrl=URL.createObjectURL(blob);varaForExcel=$("<adownload='"+downloadTitle+"'><spanclass='forExcel'>下载excel</span></a>").attr("href",objectUrl);$("body").append(aForExcel);$(".forExcel").click();aForExcel.remove();}var_h=$(window).height();var$div=$("<div/>");$div.dialog({"modal":true,"resizable":false,"showmax":false,"maxHeight":false,"maxWidth":false,"minHeight":600,"minWidth":50,"width":"100%","height":_h,"draggable":false,"title":filename,"open":function(){var$ifr="<iframeframeborder='0'width='100%'filename='"+filename+"'height='100%'id='fileImportIO'src='../struts/data/spread_ui.ftl'></iframe>";$div.append($ifr);$("#fileImportIO").data("fileIO",blob);},"close":function(event,ui){parent.$("#fileImportIO").attr("src","about:blank");$(event.target).closest("#wapper").empty().remove();}});}}xhr.send();
2.发送文件流
varxhr=newXMLHttpRequest();xhr.open("POST",'/map/download!save',true);xhr.onload=function(oEvent){if(this.status==200){if(this.response=="success"){alert(this.response);}}};xhr.send(blob);
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。