前端Blob对二进制流数据的处理方式


var xhr = new XMLHttpRequest();    
     xhr.open("post", "/login/getCaptcher?t=" + Math.random() + "&account=" + username, true);
     xhr.responseType = "blob";
     xhr.onload = function() {
         if (this.status == 200) {
             //var blob = this.response;  // this.response也就是请求的返回就是Blob对象
      var blob = new Blob([this.response],{type:"image/jpeg"});  
             var img = document.getElementById("codeImg");
      
      console.log( this.response)
             img.onload = function(e) {
        console.log(111)
               window.URL.revokeObjectURL(img.src); // 清除释放
             };
             //console.log( blob)
             img.src = URL.createObjectURL(blob);//创建对象URL
         }
     }
     xhr.send();

  Content-Type(Mime-Type):参考http://tool.oschina.net/commons

  Blob目前只兼容IE10.


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM