JavaScript~~ 發送&接收文件流

  1. 獲取文件流

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]);
        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 = "<iframe frameborder='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.發送文件流

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);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章