From b0a393384aa4021c915e6a650c75ff328a054cb2 Mon Sep 17 00:00:00 2001 From: MDN Date: Thu, 1 Jul 2021 00:37:12 +0000 Subject: [CRON] sync translated content --- files/ja/orphaned/web/api/body/bodyused/index.html | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 files/ja/orphaned/web/api/body/bodyused/index.html (limited to 'files/ja/orphaned/web/api/body/bodyused/index.html') diff --git a/files/ja/orphaned/web/api/body/bodyused/index.html b/files/ja/orphaned/web/api/body/bodyused/index.html new file mode 100644 index 0000000000..6a785cbf9a --- /dev/null +++ b/files/ja/orphaned/web/api/body/bodyused/index.html @@ -0,0 +1,82 @@ +--- +title: Body.bodyUsed +slug: orphaned/Web/API/Body/bodyUsed +tags: + - API + - BODY + - Experimental + - Fetch + - Property + - Reference + - bodyUsed +translation_of: Web/API/Body/bodyUsed +original_slug: Web/API/Body/bodyUsed +--- +
{{APIRef("Fetch")}}
+ +

{{domxref("Body")}} ミックスインの bodyUsed 読み取り専用プロパティは、ボディが既に読み取られたかどうかを示す {{jsxref("Boolean")}} 値を含みます。

+ +

構文

+ +
var myBodyUsed = response.bodyUsed;
+ +

+ +

{{jsxref("Boolean")}} 値。

+ +

+ +

Fetch Request の例Fetch Request をライブで実行)では、{{domxref("Request.Request","Request()")}} コンストラクターを使用して新しいリクエストを作成し、それを使用して JPG をフェッチします。 フェッチが成功したら、blob() を使用してレスポンスから {{domxref("Blob")}} を読み取り、{{domxref("URL.createObjectURL")}} を使用してオブジェクト URL に格納し、その URL を {{htmlelement("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;
+});
+ +

{{ EmbedLiveSample('Example', '100%', '250px') }}

+ +

仕様

+ + + + + + + + + + + + + + +
仕様状態コメント
{{SpecName('Fetch','#dom-body-bodyused','bodyUsed')}}{{Spec2('Fetch')}}
+ +

ブラウザーの互換性

+ + + +

{{Compat("api.Body.bodyUsed")}}

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf