構文
var myBodyUsed = response.bodyUsed;
値
Boolean
値。
例
Fetch Request の例(Fetch Request をライブで実行)では、Request()
コンストラクターを使用して新しいリクエストを作成し、それを使用して JPG をフェッチします。 フェッチが成功したら、blob()
を使用してレスポンスから Blob
を読み取り、URL.createObjectURL
を使用してオブジェクト URL に格納し、その URL を <img>
要素のソースとして設定して画像を表示します。
response.blob()
の呼び出し前後に、response.bodyUsed
をコンソールに記録していることに注目してください。 その時点でボディが読み取られたかによるため、これは呼び出し前では false
を返し、その後では true
を返します。
HTML の内容
<img class="my-image" src="https://wikipedia.org/static/images/project-logos/frwiki-1.5x.png">
JS の内容
var myImage = document.querySelector('.my-image');
fetch('https://upload.wikimedia.org/wikipedia/commons/7/77/Delete_key1.jpg').then(function(response) {
console.log(response.bodyUsed);
var res = response.blob();
console.log(response.bodyUsed);
return res;
}).then(function(response) {
var objectURL = URL.createObjectURL(response);
myImage.src = objectURL;
});
仕様
仕様 | 状態 | コメント |
---|---|---|
Fetch bodyUsed の定義 |
現行の標準 |
ブラウザーの互換性
BCD tables only load in the browser
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.