可能重複:
Getting BLOB data from XHR requestXMLHTTPRequest的響應返回null
我試圖從我的服務器獲取的圖像動態,但XMLHttpRequest對象在響應返回null。谷歌Chrome網絡工具告訴我,他裝載的day1.jpg,但BLOB變量爲空...
var xhr = new XMLHttpRequest(), blob;
xhr.open("GET", "day1.jpg", true);
// Set the responseType to blob
xhr.responseType = "blob";
xhr.addEventListener("load", function() {
if (xhr.status === 200) {
console.log("Image retrieved");
blob = xhr.response;
console.log("blob: " + blob);
}
}, false);
// Send XHR
xhr.send();
輸出是:
Image retrieved
blob: null
如果它的返回狀態代碼200和實際運行存在不應該是一個問題上的鍍鉻側的錯誤。嘗試將console.log(「blob:」+ xhr.response)設置爲grins。 – Snuffleupagus 2012-03-05 17:54:56
blob = xhr.response; console.log(「blob:」+ blob);與console.log(「blob:」+ xhr.response) – 2012-03-05 19:19:53
*應該*完全一樣,就像上面的代碼*應該*一樣工作。 ; p – Snuffleupagus 2012-03-05 19:21:11