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();