ajax接收二进制图片

ajax接受二进制图片

var url = "http://192.168.1.25/upload/banner/fr_1706131908589351732.jpg";
    var xhr = new XMLHttpRequest();
    xhr.open('GET', url, true);
    xhr.responseType = "blob";
    //xhr.setRequestHeader("client_type", "DESKTOP_WEB");
    //xhr.setRequestHeader("desktop_web_access_key", _desktop_web_access_key);
    xhr.onload = function () {
        if (this.status == 200) {
            var blob = this.response;
            var img = document.createElement("img");
            img.onload = function (e) {
                window.URL.revokeObjectURL(img.src);
            };
            img.src = window.URL.createObjectURL(blob);
            $("#title").html(img);
        }
    }
    xhr.send();


你可能感兴趣的:(JS)