前端使用blob展示二進制的圖片


//DOM
var img = document.getElementById('img')
//Ajax
var xhr = new XMLHttpRequest()
// 設置返回類型為blob
xhr.responseType = "blob";
xhr.addEventListener('load',() => {
console.log(xhr.response);
var blob = xhr.response
// 給img賦值
img.src = window.URL.createObjectURL(blob)
})
//ajax的請求地址 方法
xhr.open('get','http://127.0.0.1:3000/v1/get/img',true)
xhr.send(null)

  請求返回二進制數據

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM