Ajax requests a picture. There is a problem with displaying the picture in binary form.

I want to request a picture through ajax

vm.ajaxGet("/img/logo.png", function(data) {
    //data,ajax
    var img = document.createElement("img");
    img.onload = function(e) {
        window.URL.revokeObjectURL(img.src); // 
    };
    img.src = window.URL.createObjectURL(new Blob([data], { type: "image/png" }));
    document.body.appendChild(img);
});

cannot display the picture. What"s wrong with the god?

resolved:

var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.responseType = "blob";//
xhr.onreadystatechange = function() {
    if (xhr.readyState == 4) {
        if (xhr.status == 200) {
            var blod = this.response;
            var src = URL.createObjectURL(blod);
        }
    }
};
xhr.send();
Mar.28,2021

refer to this article: ajax requests and processes binary streams (picture)
https://codeshelper.com/q/10.


1. Check whether your file stream is a binary stream or a base64 stream
2. window.URL.revokeObjectURL (img.src) is it because this line of code is affected, comment out

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eba71c-27d3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eba71c-27d3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?