JavaScript~~发送&接收文件流
获取文件流
创新互联公司于2013年创立,是专业互联网技术服务公司,拥有项目成都网站设计、网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元漳浦做网站,已为上家服务,为漳浦各地企业和个人服务,联系电话:18980820575
var url = "/map/download?_beanid="+_beanid+"&buttonid="+buttonid; var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = "blob"; xhr.onload = function() { if (this.status == 200) { //var blob = this.response; var blob = new Blob([this.response]); /*if(d.headers('content-disposition').indexOf('filename') != -1){ downloadTitle = d.headers('content-disposition').split(';')[1].split('=')[1]; downloadTitle = decodeURI(downloadTitle); }待用*/ if(typeof window.navigator.msSaveBlob !== 'undefined'){ window.navigator.msSaveBlob(blob, downloadTitle); }else{ var objectUrl = URL.createObjectURL(blob); var aForExcel = $("下载excel").attr("href",objectUrl); $("body").append(aForExcel); $(".forExcel").click(); aForExcel.remove(); } var _h = $(window).height(); var $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 = ""; $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.发送文件流
var xhr = new XMLHttpRequest(); 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);
当前标题:JavaScript~~发送&接收文件流
网站链接:http://scjbc.cn/article/gsgdhp.html