前端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